首页 > 解决方案 > 如果特定消息来自特定用户,我希望我的不和谐机器人做出响应

问题描述

到目前为止,我设法找到的最佳解决方案是检查用户 ID。

@client.event
async def on_message(message):

    if(message.author == client.user):  #if message is coming from the bot itself
        return

    
    if(message.author.id == 103001222035981612 and message.content.startswith == 'Yo'):
            await message.channel.send('Hello {}'.format(message.author.name))
    
        
    #await message.channel.send(message.content)

client.run(TOKEN)

最终发生的是,无论我说什么,机器人都会做出响应,这不是我想要它做的。我尝试了其他一些方法,但它们都没有任何帮助。我很感激我能得到的任何帮助。谢谢!

标签: pythondiscorddiscord.py

解决方案


确保在最后添加

*await client.process_commands(message)*

例子:

@client.event   
async def on_message(message): 
 
  if message.author == client.user:
    return
  if client.user.mentioned_in(message):
     await message.channel.send("hey!")
  await client.process_commands(message)

推荐阅读