class Discordrb::Attachment

An attachment to a message

Attributes

content_type[R]

@return [String, nil] the attachment’s media type.

description[R]

@return [String, nil] the attachment’s description.

ephemeral[R]

@return [true, false] whether this attachment is ephemeral.

ephemeral?[R]

@return [true, false] whether this attachment is ephemeral.

filename[R]

@return [String] the attachment’s filename.

height[R]

@return [Integer, nil] the height of an image file, in pixels, or ‘nil` if the file is not an image.

message[R]

@return [Message] the message this attachment belongs to.

proxy_url[R]

@return [String] the attachment’s proxy URL - I’m not sure what exactly this does, but I think it has something to

do with CDNs.
size[R]

@return [Integer] the attachment’s file size in bytes.

url[R]

@return [String] the CDN URL this attachment can be downloaded at.

width[R]

@return [Integer, nil] the width of an image file, in pixels, or ‘nil` if the file is not an image.

Public Class Methods

new(data, message, bot) click to toggle source

@!visibility private

# File lib/discordrb/data/attachment.rb, line 41
def initialize(data, message, bot)
  @bot = bot
  @message = message

  @id = data['id'].to_i
  @url = data['url']
  @proxy_url = data['proxy_url']
  @filename = data['filename']

  @size = data['size']

  @width = data['width']
  @height = data['height']

  @description = data['description']
  @content_type = data['content_type']

  @ephemeral = data['ephemeral']
end

Public Instance Methods

image?() click to toggle source

@return [true, false] whether this file is an image file.

# File lib/discordrb/data/attachment.rb, line 62
def image?
  !(@width.nil? || @height.nil?)
end
spoiler?() click to toggle source

@return [true, false] whether this file is tagged as a spoiler.

# File lib/discordrb/data/attachment.rb, line 67
def spoiler?
  @filename.start_with? 'SPOILER_'
end