[英]How do I make my discord bot respond when a specific user sends a message in the channel?
[英]how do i use user's ID for matching it with a condition so that when the user sends message to channel, the bot can do specific tasks for the user
I have tried:
if message.channel.category.id == 774267322687815710:
if user.id == 415884831805931551:
await message.add_reaction("🔥")
我已经尝试过了,但似乎我无法让它适用于用户发送的消息,它只获取用户的 id
您必须获取消息的作者,而不仅仅是user.id
因为您还没有定义user
。
请查看以下事件:
@client.event / @bot.event / @commands.Cog.listener # Depends on what you use
async def on_message(message):
if message.channel.category.id == CategoryID:
if message.author.id == UserID: # Get the ID of the AUTHOR
await message.add_reaction("🔥") # If the ID is correct
else:
return # If the ID is incorrect/does not match do nothing
您可能还想查看文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.