首页 > 解决方案 > 我做了一个自动响应特定消息的命令。该命令有效,但它使我所有其他命令都不起作用(discord.py 重写)

问题描述

这是我在打招呼时用于命令响应的代码。这将起作用,但是如果我在它们都不起作用之后尝试使用命令,并且如果我将它从我的代码中取出,那么它会再次起作用。使用命令时没有错误代码。我真的不知道如何解决这个问题,有人知道为什么会这样吗?如果是这样,我该如何解决?

@client.event
async def on_message(message):
    channel = client.get_channel(CHANNEL)
    hello = "hello"
    if message.content.count(hello) > 0:
        message = "Whats up!"
        await channel.send(message)

标签: pythondiscord.py-rewrite

解决方案


使用on_message事件时,您需要process_commands()允许您的命令工作:

@client.event
async def on_message(message):
    await client.process_commands(message)

    # checking against lower case string will be more consistent with finding more "hello"s
    if message.content.lower().count("hello") > 0:
        await message.channel.send("What's up!")

参考:

  • Bot.process_commands()- “如果你选择覆盖on_message()事件,那么你也应该调用这个协程。”

推荐阅读