我如何使用用户 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

您也许还想看看 docs