Class: Discordrb::Webhooks::View::SelectMenuBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/webhooks/view.rb

Overview

A builder to assist in adding options to select menus.

Instance Method Summary collapse

Constructor Details

#initialize(custom_id, options = [], placeholder = nil, min_values = nil, max_values = nil, disabled = nil, select_type: :string_select, id: nil, required: nil) ⇒ SelectMenuBuilder

Returns a new instance of SelectMenuBuilder.



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/discordrb/webhooks/view.rb', line 162

def initialize(custom_id, options = [], placeholder = nil, min_values = nil, max_values = nil, disabled = nil, select_type: :string_select, id: nil, required: nil)
  @id = id
  @custom_id = custom_id
  @options = options
  @placeholder = placeholder
  @min_values = min_values
  @max_values = max_values
  @disabled = disabled
  @select_type = select_type
  @required = required
end

Instance Method Details

#option(label:, value:, description: nil, emoji: nil, default: nil) ⇒ Object

Add an option to this select menu.

Parameters:

  • label (String)

    The title of this option.

  • value (String)

    The value that this option represents.

  • description (String, nil) (defaults to: nil)

    An optional description of the option.

  • emoji (#to_h, String, Integer) (defaults to: nil)

    An emoji ID, or unicode emoji to attach to the button. Can also be an object that responds to #to_h which returns a hash in the format of { id: Integer, name: string }.

  • default (true, false, nil) (defaults to: nil)

    Whether this is the default selected option.



181
182
183
184
185
186
187
188
189
190
# File 'lib/discordrb/webhooks/view.rb', line 181

def option(label:, value:, description: nil, emoji: nil, default: nil)
  emoji = case emoji
          when Integer, String
            emoji.to_i.positive? ? { id: emoji } : { name: emoji }
          else
            emoji&.to_h
          end

  @options << { label: label, value: value, description: description, emoji: emoji, default: default }
end