Class: Discordrb::Interactions::OptionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data/interaction.rb

Overview

A builder for defining slash commands options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsArray<Hash> (readonly)

Returns:

  • (Array<Hash>)


328
329
330
# File 'lib/discordrb/data/interaction.rb', line 328

def options
  @options
end

Instance Method Details

#boolean(name, description, required: nil) ⇒ Object

Returns Hash.

Parameters:

  • name (String, Symbol)

    The name of the argument.

  • description (String)

    A description of the argument.

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

    Whether this option must be provided.

Returns:

  • Hash



393
394
395
# File 'lib/discordrb/data/interaction.rb', line 393

def boolean(name, description, required: nil)
  option(TYPES[:boolean], name, description, required: required)
end

#channel(name, description, required: nil) ⇒ Object

Returns Hash.

Parameters:

  • name (String, Symbol)

    The name of the argument.

  • description (String)

    A description of the argument.

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

    Whether this option must be provided.

Returns:

  • Hash



409
410
411
# File 'lib/discordrb/data/interaction.rb', line 409

def channel(name, description, required: nil)
  option(TYPES[:channel], name, description, required: required)
end

#integer(name, description, required: nil, choices: nil) ⇒ Object

Returns Hash.

Parameters:

  • name (String, Symbol)

    The name of the argument.

  • description (String)

    A description of the argument.

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

    Whether this option must be provided.

  • choices (Hash, nil) (defaults to: nil)

    Available choices, mapped as Name => Value.

Returns:

  • Hash



385
386
387
# File 'lib/discordrb/data/interaction.rb', line 385

def integer(name, description, required: nil, choices: nil)
  option(TYPES[:integer], name, description, required: required, choices: choices)
end

#mentionable(name, description, required: nil) ⇒ Object

Returns Hash.

Parameters:

  • name (String, Symbol)

    The name of the argument.

  • description (String)

    A description of the argument.

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

    Whether this option must be provided.

Returns:

  • Hash



425
426
427
# File 'lib/discordrb/data/interaction.rb', line 425

def mentionable(name, description, required: nil)
  option(TYPES[:mentionable], name, description, required: required)
end

#role(name, description, required: nil) ⇒ Object

Returns Hash.

Parameters:

  • name (String, Symbol)

    The name of the argument.

  • description (String)

    A description of the argument.

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

    Whether this option must be provided.

Returns:

  • Hash



417
418
419
# File 'lib/discordrb/data/interaction.rb', line 417

def role(name, description, required: nil)
  option(TYPES[:role], name, description, required: required)
end

#string(name, description, required: nil, choices: nil) ⇒ Object

Returns Hash.

Parameters:

  • name (String, Symbol)

    The name of the argument.

  • description (String)

    A description of the argument.

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

    Whether this option must be provided.

  • choices (Hash, nil) (defaults to: nil)

    Available choices, mapped as Name => Value.

Returns:

  • Hash



376
377
378
# File 'lib/discordrb/data/interaction.rb', line 376

def string(name, description, required: nil, choices: nil)
  option(TYPES[:string], name, description, required: required, choices: choices)
end

#subcommand(name, description) {|| ... } ⇒ Object

Returns Hash.

Examples:

bot.register_application_command(:test, 'Test command') do |cmd|
  cmd.subcommand(:echo) do |sub|
    sub.string('message', 'What to echo back', required: true)
  end
end

Parameters:

  • name (String, Symbol)

    The name of the subcommand.

  • description (String)

    A description of the subcommand.

Yield Parameters:

Returns:

  • Hash



345
346
347
348
349
350
# File 'lib/discordrb/data/interaction.rb', line 345

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.

Examples:

bot.register_application_command(:test, 'Test command') do |cmd|
  cmd.subcommand_group(:fun) do |group|
    group.subcommand(:8ball) do |sub|
      sub.string(:question, 'What do you ask the mighty 8ball?')
    end
  end
end

Parameters:

  • name (String, Symbol)

    The name of the subcommand group.

  • description (String)

    A description of the subcommand group.

Yield Parameters:

Returns:

  • Hash



364
365
366
367
368
369
# File 'lib/discordrb/data/interaction.rb', line 364

def subcommand_group(name, description)
  builder = OptionBuilder.new
  yield builder

  option(TYPES[:subcommand_group], name, description, options: builder.to_a)
end

#to_aArray<Hash>

Returns:

  • (Array<Hash>)


446
447
448
# File 'lib/discordrb/data/interaction.rb', line 446

def to_a
  @options
end

#user(name, description, required: nil) ⇒ Object

Returns Hash.

Parameters:

  • name (String, Symbol)

    The name of the argument.

  • description (String)

    A description of the argument.

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

    Whether this option must be provided.

Returns:

  • Hash



401
402
403
# File 'lib/discordrb/data/interaction.rb', line 401

def user(name, description, required: nil)
  option(TYPES[:user], name, description, required: required)
end