这是我打招呼时用于命令响应的代码。这将起作用,但是如果我在所有命令都不起作用后尝试使用命令,并且从代码中删除了该命令,它将再次起作用。使用命令时没有错误代码。我真的对如何解决此问题迷失了,谁能知道为什么会这样,如果可以的话,我该如何解决?
@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)
答案 0 :(得分:0)
使用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()
事件,那么您也应该调用此协程。”