<small id='8OD8W'></small><noframes id='8OD8W'>

    <tfoot id='8OD8W'></tfoot>

      <i id='8OD8W'><tr id='8OD8W'><dt id='8OD8W'><q id='8OD8W'><span id='8OD8W'><b id='8OD8W'><form id='8OD8W'><ins id='8OD8W'></ins><ul id='8OD8W'></ul><sub id='8OD8W'></sub></form><legend id='8OD8W'></legend><bdo id='8OD8W'><pre id='8OD8W'><center id='8OD8W'></center></pre></bdo></b><th id='8OD8W'></th></span></q></dt></tr></i><div id='8OD8W'><tfoot id='8OD8W'></tfoot><dl id='8OD8W'><fieldset id='8OD8W'></fieldset></dl></div>
      <legend id='8OD8W'><style id='8OD8W'><dir id='8OD8W'><q id='8OD8W'></q></dir></style></legend>

      • <bdo id='8OD8W'></bdo><ul id='8OD8W'></ul>

    1. 如何使用带空格的命令名称?

      时间:2023-09-09

            <legend id='XSXd5'><style id='XSXd5'><dir id='XSXd5'><q id='XSXd5'></q></dir></style></legend>
              <tbody id='XSXd5'></tbody>
              <bdo id='XSXd5'></bdo><ul id='XSXd5'></ul>
            • <small id='XSXd5'></small><noframes id='XSXd5'>

              1. <tfoot id='XSXd5'></tfoot>
                <i id='XSXd5'><tr id='XSXd5'><dt id='XSXd5'><q id='XSXd5'><span id='XSXd5'><b id='XSXd5'><form id='XSXd5'><ins id='XSXd5'></ins><ul id='XSXd5'></ul><sub id='XSXd5'></sub></form><legend id='XSXd5'></legend><bdo id='XSXd5'><pre id='XSXd5'><center id='XSXd5'></center></pre></bdo></b><th id='XSXd5'></th></span></q></dt></tr></i><div id='XSXd5'><tfoot id='XSXd5'></tfoot><dl id='XSXd5'><fieldset id='XSXd5'></fieldset></dl></div>

                本文介绍了如何使用带空格的命令名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                当python bot中的命令之间有空格时如何使bot工作.我知道我们可以使用 sub-command 或 on_message 来做到这一点,但是有没有其他选项可以只针对选定的命令而不是所有命令来做到这一点.

                How to make bot works when there is a space between commands in python bot. I know we can do that using sub-command or on_message but is there any another option to do that for only selected commands not for all commands.

                以下代码将不起作用.

                @bot.command(pass_context=True)
                async def mobile phones(ctx):
                    msg = "Pong. {0.author.mention}".format(ctx.message)
                    await bot.say(msg)
                

                所以我尝试使用别名,但它仍然无法正常工作.

                So I tried using alias but still it won't working.

                @bot.command(pass_context=True, aliases=['mobile phones'])
                async def phones(ctx):
                    msg = "Pong. {0.author.mention}".format(ctx.message)
                    await bot.say(msg)
                

                推荐答案

                严格来说,你不能.由于 discord.py 的命令名称以空格结尾,如 views.py 中所定义.然而,有一些选择:重新编写 discord.py 视图如何处理消息(我不推荐这样做),使用 on_messagemessage.content.startswith,或使用组.

                Strictly to say, you can't. Since discord.py's command names ends with space, as defined in views.py. There are, however, a few options: re write how discord.py views handle messages (I wouldn't recommend this), use on_message and message.content.startswith, or use groups.

                由于 on_message 使用起来相当简单,因此我将向您展示如何破解"group 语法以允许命令名称带有空格.

                Since on_message is fairly straight forward to use, I will instead show you how you can "hack" the group syntax to allow command name with spaces.

                class chain_command:
                    def __init__(self, name, **kwargs):
                        names = name.split()
                        self.last = names[-1]
                        self.names = iter(names[:-1])
                        self.kwargs = kwargs
                
                    @staticmethod
                    async def null():
                        return
                
                    def __call__(self, func):
                        from functools import reduce
                        return reduce(lambda x, y: x.group(y)(self.null), self.names, bot.group(next(self.names))(self.null)).command(self.last, **self.kwargs)(func)
                
                @chain_command("mobile phones", pass_context=True)
                async def mobile_phones(ctx):
                    msg = "Pong. {0.author.mention}".format(ctx.message)
                    await bot.say(msg)
                

                不和谐:

                me: <prefix>mobile phones
                bot: Pong. @me
                

                这篇关于如何使用带空格的命令名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:删除“找不到命令"错误 discord.py 下一篇:让不和谐机器人每 10 秒改变一次播放状态

                相关文章

                最新文章

                  <bdo id='PLGtG'></bdo><ul id='PLGtG'></ul>

                <small id='PLGtG'></small><noframes id='PLGtG'>

                <legend id='PLGtG'><style id='PLGtG'><dir id='PLGtG'><q id='PLGtG'></q></dir></style></legend>

                  1. <i id='PLGtG'><tr id='PLGtG'><dt id='PLGtG'><q id='PLGtG'><span id='PLGtG'><b id='PLGtG'><form id='PLGtG'><ins id='PLGtG'></ins><ul id='PLGtG'></ul><sub id='PLGtG'></sub></form><legend id='PLGtG'></legend><bdo id='PLGtG'><pre id='PLGtG'><center id='PLGtG'></center></pre></bdo></b><th id='PLGtG'></th></span></q></dt></tr></i><div id='PLGtG'><tfoot id='PLGtG'></tfoot><dl id='PLGtG'><fieldset id='PLGtG'></fieldset></dl></div>
                  2. <tfoot id='PLGtG'></tfoot>