Search code examples
pythonif-statementdiscorduserid

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("🔥")

I have tried this but seems like I cannot make it work for the message that is being sent by the user, it only fetches the user's id


Solution

  • You have to get the author of a message instead of just user.id as you also have not defined user.

    Have a look at the following event instead:

    @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
    

    You maybe also want to take a look at the docs