Class: Discorb::SelectMenu

Inherits:
Component show all
Defined in:
lib/discorb/components.rb

Overview

Represents a select menu component.

Defined Under Namespace

Classes: Option

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

from_hash, to_payload

Constructor Details

#initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1) -> SelectMenu

Initialize a new select menu.

Parameters:

  • custom_id (String, Symbol)

    Custom ID of the select menu.

  • options (Array<Discorb::SelectMenu::Option>)

    The options of the select menu.

  • placeholder (String) (defaults to: nil)

    The placeholder of the select menu.

  • min_values (Integer) (defaults to: 1)

    The minimum number of values.

  • max_values (Integer) (defaults to: 1)

    The maximum number of values.



195
196
197
198
199
200
201
# File 'lib/discorb/components.rb', line 195

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

Instance Attribute Details

#custom_id -> String

Returns The custom ID of the select menu.

Returns:

  • (String)

    The custom ID of the select menu.



175
176
177
# File 'lib/discorb/components.rb', line 175

def custom_id
  @custom_id
end

#disabled -> Boolean Also known as: disabled?

Returns Whether the select menu is disabled.

Returns:

  • (Boolean)

    Whether the select menu is disabled.



183
184
185
# File 'lib/discorb/components.rb', line 183

def disabled
  @disabled
end

#max_values -> Integer

Returns The maximum number of values.

Returns:

  • (Integer)

    The maximum number of values.



181
182
183
# File 'lib/discorb/components.rb', line 181

def max_values
  @max_values
end

#min_values -> Integer

Returns The minimum number of values.

Returns:

  • (Integer)

    The minimum number of values.



179
180
181
# File 'lib/discorb/components.rb', line 179

def min_values
  @min_values
end

#options -> Array<SelectMenu::Option>

Returns The options of the select menu.

Returns:



177
178
179
# File 'lib/discorb/components.rb', line 177

def options
  @options
end

Instance Method Details

#to_hash -> Hash

Converts the select menu to a hash.

Returns:

  • (Hash)

    A hash representation of the select menu.

See Also:



209
210
211
212
213
214
215
216
217
218
# File 'lib/discorb/components.rb', line 209

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