为了账号安全,请及时绑定邮箱和手机立即绑定

为什么on_message停止命令工作?

为什么on_message停止命令工作?

杨__羊羊 2019-07-31 11:02:50
为什么on_message停止命令工作?基本上,一切似乎工作正常并启动,但由于某种原因我不能调用任何命令。我一直在寻找一个小时,看着示例/观看视频,我不能为我的生活弄清楚出了什么问题。代码如下:import discordimport asynciofrom discord.ext import commands bot = commands.Bot(command_prefix = '-')@bot.event async def on_ready():     print('Logged in as')     print(bot.user.name)     print(bot.user.id)     print('------')@bot.event async def on_message(message):     if message.content.startswith('-debug'):         await message.channel.send('d')@bot.command(pass_context=True)async def ping(ctx):     await ctx.channel.send('Pong!')@bot.command(pass_context=True)async def add(ctx, *, arg):     await ctx.send(arg)我在on_message中的调试输出实际上工作并响应,并且整个机器人运行没有任何异常,但它只是不会调用命令。
查看完整描述

1 回答

?
芜湖不芜

TA贡献1796条经验 获得超7个赞

从重写文档:

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

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

    await bot.process_commands(message)

默认on_message包含对此协同程序的调用,但是当您使用自己的协程覆盖它时on_message,您需要自己调用它。


查看完整回答
反对 回复 2019-07-31
  • 1 回答
  • 0 关注
  • 568 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信