为什么我无法运行我的机器人命令 (discord.py)?



我有一些问题,当我试图创建一个机器人
这是我的代码的一部分:

@client.event
async def on_message(message):
if message.author == client.user:
return
await client.process_commands(message)

@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
general_channel = client.get_channel(874180398475804695)
await general_channel.send('I am ready',delete_after=10)
@client.event
async def on_message(message):
if any(word in message.content for word in rude_word):
await message.reply('Hey man, that word is not allowed here .',delete_after=2)
await message.delete()
@client.command(name='ping')
async def ping(message):
await message.reply('pong')

当我输入command时,bot不工作。
但是,如果我删除的部分:

@client.event
async def on_message(message):
if any(word in message.content for word in rude_word):
await message.reply('Hey man, that word is not allowed here .',delete_after=2)
await message.delete()

命令恢复正常。
另一种情况,我删除:

@client.command(name='ping')
async def ping(message):
await message.reply('pong')

机器人仍然可以工作(删除消息)。然而,当我把这两个结合起来时,@client.command不起作用。我已经尽力想弄明白了,但还是不明白。我该怎么做才能让这些命令工作呢?

问题在于on_message。您需要在discord.pyFAQ中提到的on_message的末尾添加await client.process_commands(message)

最新更新