class Discorb::Command::Command::GroupCommand
Represents the command with subcommands.
Attributes
@return [Array<Discorb::Command::Command::SlashCommand, Discorb::Command::Command::SubcommandGroup>] The subcommands of the command.
@return [String] The description of the command.
Public Class Methods
@!visibility private
Discorb::Command::Command::new
# File lib/discorb/command.rb, line 250 def initialize(name, description, guild_ids, type, client) super(name, guild_ids, block, type) @description = description @commands = [] @client = client @id_map = Discorb::Dictionary.new end
Public Instance Methods
Add new subcommand group.
@param [String] command_name Group name. @param [String] description Group description.
@yield Block to execute as the command. It can be used to define sub-commands. @yieldself [Discorb::Command::Command::SubcommandGroup] Group command.
@return [Discorb::Command::Command::SubcommandGroup] Command
object.
@see file:docs/slash_command.md
# File lib/discorb/command.rb, line 284 def group(command_name, description, &block) command = Discorb::Command::Command::SubcommandGroup.new(command_name, description, @name, @client) command.instance_eval(&block) if block_given? @commands << command command end
Add new subcommand.
@param (see Discorb::Command::Handler#slash
) @return [Discorb::Command::Command::SlashCommand] The added subcommand.
# File lib/discorb/command.rb, line 264 def slash(command_name, description, options = {}, &block) command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], block, 1, @name) @client.bottom_commands << command @commands << command command end
@!visibility private
# File lib/discorb/command.rb, line 301 def to_hash options_payload = @commands.map do |command| if command.is_a?(SlashCommand) { name: command.name, description: command.description, default_permission: true, type: 1, options: command.to_hash[:options], } else { name: command.name, description: command.description, default_permission: true, type: 2, options: command.commands.map { |c| c.to_hash.merge(type: 1) }, } end end { name: @name, default_permission: @enabled, description: @description, options: options_payload, } end
Returns the command name.
@return [String] The command name.
# File lib/discorb/command.rb, line 296 def to_s @name end