Class: Discordrb::Interactions::OptionBuilder
- Inherits:
-
Object
- Object
- Discordrb::Interactions::OptionBuilder
- Defined in:
- lib/discordrb/data/interaction.rb
Overview
A builder for defining slash commands options.
Constant Summary collapse
- CHANNEL_TYPES =
Channel types that can be provided to #channel
{ text: 0, dm: 1, voice: 2, group_dm: 3, category: 4, news: 5, store: 6, news_thread: 10, public_thread: 11, private_thread: 12, stage: 13 }.freeze
Instance Attribute Summary collapse
- #options ⇒ Array<Hash> readonly
Instance Method Summary collapse
-
#attachment(name, description, required: nil) ⇒ Object
Hash.
-
#boolean(name, description, required: nil) ⇒ Object
Hash.
-
#channel(name, description, required: nil, types: nil) ⇒ Object
Hash.
-
#integer(name, description, required: nil, min_value: nil, max_value: nil, choices: nil, autocomplete: nil) ⇒ Object
Hash.
-
#mentionable(name, description, required: nil) ⇒ Object
Hash.
-
#number(name, description, required: nil, min_value: nil, max_value: nil, choices: nil, autocomplete: nil) ⇒ Object
Hash.
-
#role(name, description, required: nil) ⇒ Object
Hash.
-
#string(name, description, required: nil, min_length: nil, max_length: nil, choices: nil, autocomplete: nil) ⇒ Object
Hash.
-
#subcommand(name, description) {|| ... } ⇒ Object
Hash.
-
#subcommand_group(name, description) {|| ... } ⇒ Object
Hash.
- #to_a ⇒ Array<Hash>
-
#user(name, description, required: nil) ⇒ Object
Hash.
Instance Attribute Details
#options ⇒ Array<Hash> (readonly)
545 546 547 |
# File 'lib/discordrb/data/interaction.rb', line 545 def @options end |
Instance Method Details
#attachment(name, description, required: nil) ⇒ Object
Returns Hash.
672 673 674 |
# File 'lib/discordrb/data/interaction.rb', line 672 def (name, description, required: nil) option(TYPES[:attachment], name, description, required: required) end |
#boolean(name, description, required: nil) ⇒ Object
Returns Hash.
618 619 620 |
# File 'lib/discordrb/data/interaction.rb', line 618 def boolean(name, description, required: nil) option(TYPES[:boolean], name, description, required: required) end |
#channel(name, description, required: nil, types: nil) ⇒ Object
Returns Hash.
635 636 637 638 |
# File 'lib/discordrb/data/interaction.rb', line 635 def channel(name, description, required: nil, types: nil) types = types&.collect { |type| type.is_a?(Numeric) ? type : CHANNEL_TYPES[type] } option(TYPES[:channel], name, description, required: required, channel_types: types) end |
#integer(name, description, required: nil, min_value: nil, max_value: nil, choices: nil, autocomplete: nil) ⇒ Object
Returns Hash.
609 610 611 612 |
# File 'lib/discordrb/data/interaction.rb', line 609 def integer(name, description, required: nil, min_value: nil, max_value: nil, choices: nil, autocomplete: nil) option(TYPES[:integer], name, description, required: required, min_value: min_value, max_value: max_value, choices: choices, autocomplete: autocomplete) end |
#mentionable(name, description, required: nil) ⇒ Object
Returns Hash.
652 653 654 |
# File 'lib/discordrb/data/interaction.rb', line 652 def mentionable(name, description, required: nil) option(TYPES[:mentionable], name, description, required: required) end |
#number(name, description, required: nil, min_value: nil, max_value: nil, choices: nil, autocomplete: nil) ⇒ Object
Returns Hash.
663 664 665 666 |
# File 'lib/discordrb/data/interaction.rb', line 663 def number(name, description, required: nil, min_value: nil, max_value: nil, choices: nil, autocomplete: nil) option(TYPES[:number], name, description, required: required, min_value: min_value, max_value: max_value, choices: choices, autocomplete: autocomplete) end |
#role(name, description, required: nil) ⇒ Object
Returns Hash.
644 645 646 |
# File 'lib/discordrb/data/interaction.rb', line 644 def role(name, description, required: nil) option(TYPES[:role], name, description, required: required) end |
#string(name, description, required: nil, min_length: nil, max_length: nil, choices: nil, autocomplete: nil) ⇒ Object
Returns Hash.
596 597 598 599 |
# File 'lib/discordrb/data/interaction.rb', line 596 def string(name, description, required: nil, min_length: nil, max_length: nil, choices: nil, autocomplete: nil) option(TYPES[:string], name, description, required: required, min_length: min_length, max_length: max_length, choices: choices, autocomplete: autocomplete) end |
#subcommand(name, description) {|| ... } ⇒ Object
Returns Hash.
562 563 564 565 566 567 |
# File 'lib/discordrb/data/interaction.rb', line 562 def subcommand(name, description) builder = OptionBuilder.new yield builder if block_given? option(TYPES[:subcommand], name, description, options: builder.to_a) end |
#subcommand_group(name, description) {|| ... } ⇒ Object
Returns Hash.
581 582 583 584 585 586 |
# File 'lib/discordrb/data/interaction.rb', line 581 def subcommand_group(name, description) builder = OptionBuilder.new yield builder option(TYPES[:subcommand_group], name, description, options: builder.to_a) end |
#to_a ⇒ Array<Hash>
702 703 704 |
# File 'lib/discordrb/data/interaction.rb', line 702 def to_a @options end |
#user(name, description, required: nil) ⇒ Object
Returns Hash.
626 627 628 |
# File 'lib/discordrb/data/interaction.rb', line 626 def user(name, description, required: nil) option(TYPES[:user], name, description, required: required) end |