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

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

    • <bdo id='C2YdX'></bdo><ul id='C2YdX'></ul>

    1. <legend id='C2YdX'><style id='C2YdX'><dir id='C2YdX'><q id='C2YdX'></q></dir></style></legend>

      前缀和非前缀命令在 python discord bot 上不能一起工

      Prefixed and non prefix commands are not working together on python discord bot(前缀和非前缀命令在 python discord bot 上不能一起工作)
      <tfoot id='ewMWo'></tfoot>

          1. <small id='ewMWo'></small><noframes id='ewMWo'>

            • <bdo id='ewMWo'></bdo><ul id='ewMWo'></ul>
                <tbody id='ewMWo'></tbody>
            • <i id='ewMWo'><tr id='ewMWo'><dt id='ewMWo'><q id='ewMWo'><span id='ewMWo'><b id='ewMWo'><form id='ewMWo'><ins id='ewMWo'></ins><ul id='ewMWo'></ul><sub id='ewMWo'></sub></form><legend id='ewMWo'></legend><bdo id='ewMWo'><pre id='ewMWo'><center id='ewMWo'></center></pre></bdo></b><th id='ewMWo'></th></span></q></dt></tr></i><div id='ewMWo'><tfoot id='ewMWo'></tfoot><dl id='ewMWo'><fieldset id='ewMWo'></fieldset></dl></div>
                <legend id='ewMWo'><style id='ewMWo'><dir id='ewMWo'><q id='ewMWo'></q></dir></style></legend>
                本文介绍了前缀和非前缀命令在 python discord bot 上不能一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                import asyncio
                import discord
                from discord.ext import commands
                from discord.ext.commands import Bot
                import chalk
                
                
                bot = commands.Bot(command_prefix='!')
                
                @bot.event
                async def on_ready():
                    await bot.change_presence(game=discord.Game(name='Test'))
                    print("All systems online and working " + bot.user.name)
                    await bot.send_message(discord.Object(id=386518608550952965), "All systems online and working")
                
                @bot.command(pass_context=True)
                async def hel(ctx):
                    await bot.say("A help message is sent to user")
                
                
                @bot.command
                async def on_message(message):
                    if message.content.startswith("ping"):
                        await bot.send_message(message.channel, "Pong")
                
                
                
                
                bot.run("TOKEN", bot=True)
                

                我试图在我的 discord 测试服务器上完成这项工作,但是当我像这样使用它时,只有第一个on_ready"和 !hel 命令有效,ping 不打印任何内容,但是当我删除 !hel命令代码部分,ping 有效,有什么方法可以让它们一起工作吗?

                I'm trying to get this work on my discord test server but when I use it like this, only the first "on_ready" and !hel command works, ping doesn't print anything, but when I delete the !hel commands code part, ping works, is there any way that I can make them work together?

                推荐答案

                使用on_message@bot.command改为@bot.event>

                Change @bot.command to @bot.event when using on_message

                在使用on_message时添加bot.process_commands

                为什么 on_message 会让我的命令停止工作?

                覆盖默认提供的 on_message 会禁止运行任何额外的命令.要解决此问题,请在 on_message 末尾添加 bot.process_commands(message) 行.例如:

                Overriding the default provided on_message forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message. For example:

                @bot.event
                async def on_message(message):
                    # do some extra stuff here
                
                    await bot.process_commands(message)
                

                http://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working

                您的代码应如下所示:

                import asyncio
                import discord
                from discord.ext import commands
                from discord.ext.commands import Bot
                import chalk
                
                
                bot = commands.Bot(command_prefix='!')
                
                @bot.event
                async def on_ready():
                    await bot.change_presence(game=discord.Game(name='Test'))
                    print("All systems online and working " + bot.user.name)
                    await bot.send_message(discord.Object(id=386518608550952965), "All systems online and working")
                
                @bot.command(pass_context=True)
                async def hel(ctx):
                    await bot.say("A help message is sent to user")
                
                
                @bot.event
                async def on_message(message):
                    if message.content.startswith("ping"):
                        await bot.send_message(message.channel, "Pong")
                
                    await bot.process_commands(message)
                
                
                bot.run("TOKEN", bot=True)
                

                这篇关于前缀和非前缀命令在 python discord bot 上不能一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                【网站声明】本站部分内容来源于互联网,旨在帮助大家更快的解决问题,如果有图片或者内容侵犯了您的权益,请联系我们删除处理,感谢您的支持!

                相关文档推荐

                How to make a discord bot that gives roles in Python?(如何制作一个在 Python 中提供角色的不和谐机器人?)
                Discord bot isn#39;t responding to commands(Discord 机器人没有响应命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“关于我吗?Discord 机器人的功能?(不和谐.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 机器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自动更改角色颜色)

                • <bdo id='ggdly'></bdo><ul id='ggdly'></ul>

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

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

                        <tfoot id='ggdly'></tfoot>
                          <tbody id='ggdly'></tbody>