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

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.



167
168
169
170
171
172
173
# 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

Instance Attribute Details

#custom_id -> String

Returns The custom ID of the select menu.

Returns:

  • (String)

    The custom ID of the select menu.



147
148
149
# File 'lib/discorb/components.rb', line 147

def custom_id
  @custom_id
end

#disabled -> Boolean (readonly) Also known as: disabled?

Returns Whether the select menu is disabled.

Returns:

  • (Boolean)

    Whether the select menu is disabled.



155
156
157
# File 'lib/discorb/components.rb', line 155

def disabled
  @disabled
end

#max_values -> Integer

Returns The maximum number of values.

Returns:

  • (Integer)

    The maximum number of values.



153
154
155
# File 'lib/discorb/components.rb', line 153

def max_values
  @max_values
end

#min_values -> Integer

Returns The minimum number of values.

Returns:

  • (Integer)

    The minimum number of values.



151
152
153
# File 'lib/discorb/components.rb', line 151

def min_values
  @min_values
end

#options -> Array<SelectMenu::Option>

Returns The options of the select menu.

Returns:



149
150
151
# File 'lib/discorb/components.rb', line 149

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:



181
182
183
184
185
186
187
188
189
190
# 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