nettirely.py 文件源码

python
阅读 71 收藏 0 点赞 0 评论 0

项目:nettirely 作者: 8Banana 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号