def on_command(self, command, arg_amount=ANY_ARGUMENTS):
"""
Creates a decorator that registers a command handler.
The argument command must include the prefix.
The command handler takes as arguments:
1. The bot instance
2. The command sender.
3. The command recipient, usually a channel.
4. Any arguments that came with the command,
split depending on the arg_amount argument.
As an example, to register a command that looks like this:
!slap nickname
You'd write something like this:
@bot.on_command("!slap", arg_amount=1)
def slap(self, sender, recipient, slappee):
...
"""
def _inner(func):
if not inspect.iscoroutinefunction(func):
raise ValueError("You can only register coroutines!")
self._command_callbacks.setdefault(command, [])\
.append((func, arg_amount))
return func
return _inner
评论列表
文章目录