Class: Rubord::SelectMenu
- Inherits:
-
Object
- Object
- Rubord::SelectMenu
- Defined in:
- lib/rubord/components/select_menu.rb
Overview
Represents a Discord select menu component.
Select menus are dropdown components that allow users to select one or multiple options from a list.
Instance Attribute Summary collapse
-
#custom_id ⇒ String
Developer-defined identifier.
-
#disabled ⇒ Boolean
Whether the select menu is disabled.
-
#max_values ⇒ Integer
Maximum number of options that can be selected.
-
#min_values ⇒ Integer
Minimum number of options that must be selected.
-
#options ⇒ Array<Hash>
List of available options.
-
#placeholder ⇒ String?
Placeholder text displayed when no option is selected.
-
#type ⇒ Integer
Component type (always 3 for select menus).
Instance Method Summary collapse
-
#add_option(label:, value:, description: nil, emoji: nil, default: false) ⇒ Rubord::SelectMenu
Adds an option to the select menu.
-
#initialize(custom_id:, placeholder: nil, min_values: 1, max_values: 1, disabled: false) ⇒ SelectMenu
constructor
Creates a new select menu component.
-
#to_h ⇒ Hash
Converts the select menu to a Discord API-compatible hash.
Constructor Details
#initialize(custom_id:, placeholder: nil, min_values: 1, max_values: 1, disabled: false) ⇒ SelectMenu
Creates a new select menu component.
77 78 79 80 81 82 83 84 85 |
# File 'lib/rubord/components/select_menu.rb', line 77 def initialize(custom_id:, placeholder: nil, min_values: 1, max_values: 1, disabled: false) @type = 3 @custom_id = custom_id @options = [] @placeholder = placeholder @min_values = min_values @max_values = max_values @disabled = disabled end |
Instance Attribute Details
#custom_id ⇒ String
Returns Developer-defined identifier.
32 33 34 |
# File 'lib/rubord/components/select_menu.rb', line 32 def custom_id @custom_id end |
#disabled ⇒ Boolean
Returns Whether the select menu is disabled.
49 50 51 |
# File 'lib/rubord/components/select_menu.rb', line 49 def disabled @disabled end |
#max_values ⇒ Integer
Returns Maximum number of options that can be selected. Defaults to 1.
46 47 48 |
# File 'lib/rubord/components/select_menu.rb', line 46 def max_values @max_values end |
#min_values ⇒ Integer
Returns Minimum number of options that must be selected. Defaults to 1.
42 43 44 |
# File 'lib/rubord/components/select_menu.rb', line 42 def min_values @min_values end |
#options ⇒ Array<Hash>
Returns List of available options.
35 36 37 |
# File 'lib/rubord/components/select_menu.rb', line 35 def @options end |
#placeholder ⇒ String?
Returns Placeholder text displayed when no option is selected.
38 39 40 |
# File 'lib/rubord/components/select_menu.rb', line 38 def placeholder @placeholder end |
#type ⇒ Integer
Returns Component type (always 3 for select menus).
29 30 31 |
# File 'lib/rubord/components/select_menu.rb', line 29 def type @type end |
Instance Method Details
#add_option(label:, value:, description: nil, emoji: nil, default: false) ⇒ Rubord::SelectMenu
Adds an option to the select menu.
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rubord/components/select_menu.rb', line 105 def add_option(label:, value:, description: nil, emoji: nil, default: false) @options << { label: label, value: value, description: description, emoji: emoji, default: default }.compact self end |
#to_h ⇒ Hash
Converts the select menu to a Discord API-compatible hash.
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rubord/components/select_menu.rb', line 124 def to_h { type: @type, custom_id: @custom_id, options: @options, placeholder: @placeholder, min_values: @min_values, max_values: @max_values, disabled: @disabled }.compact end |