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

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

      <tfoot id='LF5nx'></tfoot>
    1. on_message() 和@bot.command 问题

      时间:2023-09-11
        <tbody id='X8G6q'></tbody>

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

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

                <legend id='X8G6q'><style id='X8G6q'><dir id='X8G6q'><q id='X8G6q'></q></dir></style></legend>
                本文介绍了on_message() 和@bot.command 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                当我的代码中有 on_message() 时,它会停止所有其他 @bot.command 命令的工作.我尝试过 await bot.process_commands(message),但这也不起作用.这是我的代码:

                When I have on_message() in my code, it stops every other @bot.command commands from working. I've tried to await bot.process_commands(message), but that doesn't work either. Here is my code that I have:

                @bot.event
                @commands.has_role("Owner")
                async def on_message(message):
                    if message.content.startswith('/lockdown'):
                        await bot.process_commands(message)
                        embed = discord.Embed(title=":warning: Do you want to activate Lock Down?", description="Type 'confirm' to activate Lock Down mode", color=0xFFFF00)
                        embed.add_field(name="u200b", value="Lock Down mode is still in early development, expect some issues")
                        channel = message.channel
                        await bot.send_message(message.channel, embed=embed)
                        msg = await bot.wait_for_message(author=message.author, content='confirm')
                        embed = discord.Embed(title=":white_check_mark: Lock Down mode successfully activated", description="To deactivate type '/lockdownstop'", color=0x00ff00)
                        embed.add_field(name="u200b", value="Lock Down mode is still in early development, expect some issues")
                        await bot.send_message(message.channel, embed=embed)
                

                推荐答案

                你必须将 await bot.process_commands(message) 放在 if 语句范围之外,<无论消息是否以/lockdown"开头,都应运行code>process_command.

                You have to place await bot.process_commands(message) outside of the if statement scope, process_command should be run regardless if the message startswith "/lockdown".

                @bot.event
                async def on_message(message):
                    if message.content.startswith('/lockdown'):
                       ...
                    await bot.process_commands(message)
                

                顺便说一句,@commands.has_role(...) 不能应用于 on_message.尽管没有任何错误(因为检查到位),但 has_role 实际上不会像您预期的那样工作.

                By the way, @commands.has_role(...) cannot be applied to on_message. Although there aren't any errors (because there’s checking in place), has_role wouldn't actually work as you would've expected.

                @has_role 装饰器的替代方案是:

                An alternative to the @has_role decorator would be:

                @bot.event
                async def on_message(message):
                    if message.channel.is_private or discord.utils.get(message.author.roles, name="Admin") is None:
                        return False
                
                    if message.content.startswith('/lockdown'):
                       ...
                    await bot.process_commands(message)
                

                这篇关于on_message() 和@bot.command 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 discord.py 中编辑消息 下一篇:将按钮组件添加到消息(discord.py)

                相关文章

                最新文章

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

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