Class: Discordrb::Webhooks::Embed
- Inherits:
-
Object
- Object
- Discordrb::Webhooks::Embed
- Defined in:
- lib/discordrb/webhooks/embeds.rb
Overview
An embed is a multipart-style attachment to a webhook message that can have a variety of different purposes and appearances.
Instance Attribute Summary collapse
-
#author ⇒ EmbedAuthor?
Author for this embed.
-
#colour ⇒ Integer?
(also: #color)
The colour of the bar to the side, in decimal form.
-
#description ⇒ String?
Description for this embed.
-
#fields ⇒ Array<EmbedField>
The fields attached to this embed.
-
#footer ⇒ EmbedFooter?
Footer for this embed.
-
#image ⇒ EmbedImage?
Image for this embed.
-
#thumbnail ⇒ EmbedThumbnail?
Thumbnail for this embed.
-
#timestamp ⇒ Time?
Timestamp for this embed.
-
#title ⇒ String?
Title of the embed that will be displayed above everything else.
-
#url ⇒ String?
URL the title should point to.
Instance Method Summary collapse
-
#<<(field) ⇒ Object
Add a field object to this embed.
-
#add_field(name: nil, value: nil, inline: nil) ⇒ Object
Convenience method to add a field to the embed without having to create one manually.
-
#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: []) ⇒ Embed
constructor
A new instance of Embed.
-
#to_hash ⇒ Hash
A hash representation of this embed, to be converted to JSON.
Constructor Details
#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: []) ⇒ Embed
Returns a new instance of Embed.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 = self.colour = colour || color @footer = @image = image @thumbnail = thumbnail @video = video @provider = provider @author = @fields = fields end |
Instance Attribute Details
#author ⇒ EmbedAuthor?
Returns author for this embed.
83 84 85 |
# File 'lib/discordrb/webhooks/embeds.rb', line 83 def @author end |
#colour ⇒ Integer? Also known as: color
Returns the colour of the bar to the side, in decimal form.
36 37 38 |
# File 'lib/discordrb/webhooks/embeds.rb', line 36 def colour @colour end |
#description ⇒ String?
Returns description for this embed.
27 28 29 |
# File 'lib/discordrb/webhooks/embeds.rb', line 27 def description @description end |
#fields ⇒ Array<EmbedField>
Returns the fields attached to this embed.
103 104 105 |
# File 'lib/discordrb/webhooks/embeds.rb', line 103 def fields @fields end |
#footer ⇒ EmbedFooter?
Returns footer for this embed.
65 66 67 |
# File 'lib/discordrb/webhooks/embeds.rb', line 65 def @footer end |
#image ⇒ EmbedImage?
Returns image for this embed.
71 72 73 |
# File 'lib/discordrb/webhooks/embeds.rb', line 71 def image @image end |
#thumbnail ⇒ EmbedThumbnail?
Returns thumbnail for this embed.
77 78 79 |
# File 'lib/discordrb/webhooks/embeds.rb', line 77 def thumbnail @thumbnail end |
#timestamp ⇒ Time?
Returns timestamp for this embed. Will be displayed just below the title.
33 34 35 |
# File 'lib/discordrb/webhooks/embeds.rb', line 33 def @timestamp end |
#title ⇒ String?
Returns title of the embed that will be displayed above everything else.
24 25 26 |
# File 'lib/discordrb/webhooks/embeds.rb', line 24 def title @title end |
#url ⇒ String?
Returns URL the title should point to.
30 31 32 |
# File 'lib/discordrb/webhooks/embeds.rb', line 30 def url @url end |
Instance Method Details
#<<(field) ⇒ Object
Add a field object to this embed.
87 88 89 |
# File 'lib/discordrb/webhooks/embeds.rb', line 87 def <<(field) @fields << field end |
#add_field(name: nil, value: nil, inline: nil) ⇒ Object
Convenience method to add a field to the embed without having to create one manually.
98 99 100 |
# 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 |
#to_hash ⇒ Hash
Returns a hash representation of this embed, to be converted to JSON.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# 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 |