Method: Discordrb::Commands::CommandContainer#command
- Defined in:
- lib/discordrb/commands/container.rb
#command(name, attributes = {}) {|event| ... } ⇒ Command
Note:
LocalJumpError
s are rescued from internally, giving bots the opportunity to use return
or break
in
their blocks without propagating an exception.
Adds a new command to the container.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/discordrb/commands/container.rb', line 61 def command(name, attributes = {}, &block) @commands ||= {} # TODO: Remove in 4.0 if name.is_a?(Array) name, *aliases = name attributes[:aliases] = aliases if attributes[:aliases].nil? Discordrb::LOGGER.warn("While registering command #{name.inspect}") Discordrb::LOGGER.warn('Arrays for command aliases is removed. Please use `aliases` argument instead.') end new_command = Command.new(name, attributes, &block) new_command.attributes[:aliases].each do |aliased_name| @commands[aliased_name] = CommandAlias.new(aliased_name, new_command) end @commands[name] = new_command end |