class Discordrb::Webhooks::Embed
An embed is a multipart-style attachment to a webhook message that can have a variety of different purposes and appearances.
Attributes
@return [Integer, nil] the colour of the bar to the side, in decimal form
@return [Integer, nil] the colour of the bar to the side, in decimal form
@return [String, nil] description for this embed
@return [Array<EmbedField>] the fields attached to this embed.
@see EmbedImage
@example Add a image to an embed
embed.image = Discordrb::Webhooks::EmbedImage.new(url: 'https://i.imgur.com/PcMltU7.jpg')
@return [EmbedImage, nil] image for this embed
@see EmbedThumbnail
@example Add a thumbnail to an embed
embed.thumbnail = Discordrb::Webhooks::EmbedThumbnail.new(url: 'https://i.imgur.com/xTG3a1I.jpg')
@return [EmbedThumbnail, nil] thumbnail for this embed
@return [Time, nil] timestamp for this embed. Will be displayed just below the title.
@return [String, nil] title of the embed that will be displayed above everything else.
@return [String, nil] URL the title should point to
Public Class Methods
# File lib/discordrb/webhooks/embeds.rb, line 7 def initialize(title: nil, description: nil, url: nil, timestamp: nil, colour: nil, color: nil, footer: nil, image: nil, thumbnail: nil, video: nil, provider: nil, author: nil, fields: []) @title = title @description = description @url = url @timestamp = timestamp self.colour = colour || color @footer = footer @image = image @thumbnail = thumbnail @video = video @provider = provider @author = author @fields = fields end
Public Instance Methods
Add a field object to this embed. @param field [EmbedField] The field to add.
# File lib/discordrb/webhooks/embeds.rb, line 87 def <<(field) @fields << field end
Convenience method to add a field to the embed without having to create one manually. @see EmbedField
@example Add a field to an embed, conveniently
embed.add_field(name: 'A field', value: "The field's content")
@param name [String] The field's name @param value [String] The field's value @param inline [true, false] Whether the field should be inlined
# File lib/discordrb/webhooks/embeds.rb, line 98 def add_field(name: nil, value: nil, inline: nil) self << EmbedField.new(name: name, value: value, inline: inline) end
Sets the colour of the bar to the side of the embed to something new. @param value [Integer, String, {Integer, Integer, Integer}, to_i, nil] The colour in decimal, hexadecimal, R/G/B decimal, or nil to clear the embeds colour
form.
# File lib/discordrb/webhooks/embeds.rb, line 42 def colour=(value) if value.nil? @colour = nil elsif value.is_a? Integer raise ArgumentError, 'Embed colour must be 24-bit!' if value >= 16_777_216 @colour = value elsif value.is_a? String self.colour = value.delete('#').to_i(16) elsif value.is_a? Array raise ArgumentError, 'Colour tuple must have three values!' if value.length != 3 self.colour = value[0] << 16 | value[1] << 8 | value[2] else self.colour = value.to_i end end
@return [Hash] a hash representation of this embed, to be converted to JSON.
# File lib/discordrb/webhooks/embeds.rb, line 106 def to_hash { title: @title, description: @description, url: @url, timestamp: @timestamp&.utc&.iso8601, color: @colour, footer: @footer&.to_hash, image: @image&.to_hash, thumbnail: @thumbnail&.to_hash, video: @video&.to_hash, provider: @provider&.to_hash, author: @author&.to_hash, fields: @fields.map(&:to_hash) } end