class Discorb::SelectMenu::Option
Represents an option of a select menu.
Attributes
@return [Boolean] Whether the option is default.
@return [String] The description of the option.
@return [Discorb::Emoji] The emoji of the option.
@return [String] The label of the option.
@return [String] The value of the option.
Public Class Methods
Creates a new option from a hash.
@param [Hash] data A hash representing the option.
@return [Discorb::SelectMenu::Option] A new option.
# File lib/discorb/components.rb, line 265 def from_hash(data) new(data[:label], data[:value], description: data[:description], emoji: data[:emoji], default: data[:default]) end
Initialize a new option.
@param [String] label The label of the option. @param [String] value The value of the option. @param [String] description The description of the option. @param [Discorb::Emoji] emoji The emoji of the option. @param [Boolean] default Whether the option is default.
# File lib/discorb/components.rb, line 215 def initialize(label, value, description: nil, emoji: nil, default: false) @label = label @value = value @description = description @emoji = emoji @default = default end
Public Instance Methods
@!visibility private
# File lib/discorb/components.rb, line 240 def hash_emoji(emoji) case emoji when UnicodeEmoji { id: nil, name: emoji.to_s, animated: false, } when CustomEmoji { id: emoji.id, name: emoji.name, animated: emoji.animated?, } end end
Converts the option to a hash.
@see discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure Official Discord API docs @return [Hash] Hash representation of the option.
# File lib/discorb/components.rb, line 229 def to_hash { label: @label, value: @value, description: @description, emoji: hash_emoji(@emoji), default: @default, } end