class Discorb::SelectMenu

Represents a select menu component.

Attributes

custom_id[RW]

@return [String] The custom ID of the select menu.

disabled[R]

@return [Boolean] Whether the select menu is disabled.

disabled?[R]

@return [Boolean] Whether the select menu is disabled.

max_values[RW]

@return [Integer] The maximum number of values.

min_values[RW]

@return [Integer] The minimum number of values.

options[RW]

@return [Array<SelectMenu::Option>] The options of the select menu.

Public Class Methods

new(custom_id, options, placeholder: nil, min_values: 1, max_values: 1) click to toggle source

Initialize a new select menu.

@param [String, Symbol] custom_id Custom ID of the select menu. @param [Array<Discorb::SelectMenu::Option>] options The options of the select menu. @param [String] placeholder The placeholder of the select menu. @param [Integer] min_values The minimum number of values. @param [Integer] max_values The maximum number of values.

# File lib/discorb/components.rb, line 167
def initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1)
  @custom_id = custom_id
  @options = options
  @placeholder = placeholder
  @min_values = min_values
  @max_values = max_values
end

Public Instance Methods

to_hash() click to toggle source

Converts the select menu to a hash.

@see discord.com/developers/docs/interactions/message-components#select-menu-object-select-menu-structure Official Discord API docs @return [Hash] A hash representation of the select menu.

# File lib/discorb/components.rb, line 181
def to_hash
  {
    type: 3,
    custom_id: @custom_id,
    options: @options.map(&:to_hash),
    placeholder: @placeholder,
    min_values: @min_values,
    max_values: @max_values,
  }
end

Private Instance Methods

hash_emoji(emoji) click to toggle source
# File lib/discorb/components.rb, line 273
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