猿问

为什么on_message停止命令工作?

为什么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中的调试输出实际上工作并响应,并且整个机器人运行没有任何异常,但它只是不会调用命令。


杨__羊羊
浏览 569回答 1
1回答

芜湖不芜

从重写文档:覆盖提供的默认值以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,您需要自己调用它。
随时随地看视频慕课网APP

相关分类

Python
我要回答