繁体   English   中英

我如何使用用户 ID 将其与条件匹配,以便当用户向频道发送消息时,机器人可以为用户执行特定任务

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM