-1

I am writing a discordbot bot the function user.bot isnt working correctly

@client.event
async on_reaction_add(reaction, user):
     if not user.bot:
          await client.wait_until_ready()
     try:
          channel = client.get_channel(welcome_channel_id)
              try:
                  await channel.send(message)
                  await reaction.remove(user)
              except Exception as e
                  raise e
              except Exception as e
                  raise e

Everything works accept the if statement, I create a message with a reaction with a bot but the bots reaction is removed. I am using Python 3.8. If u need any extra information pls tell me.

2
  • reaction.remove() sure does sound like something that removes a reaction, right? Commented Nov 15, 2021 at 20:52
  • Yes but it still should not do it if the bot placed the reaction thats why there is a if not user.bot: Commented Nov 15, 2021 at 20:54

1 Answer 1

2

Your try block executed every time, after the if statement is evaluated.

I'm assuming it should only execute if the if statement evaluates to true:

if not user.bot:
     await client.wait_until_ready()
     try:
          channel = client.get_channel(welcome_channel_id)
          await channel.send(message)
          await reaction.remove(user)
      except Exception as e
              raise e

But raise e negates the whole point of using a try/catch block - it has no effect.

The above code is equivalent to

if not user.bot:
     await client.wait_until_ready()
     channel = client.get_channel(welcome_channel_id)
     await channel.send(message)
     await reaction.remove(user)
Sign up to request clarification or add additional context in comments.

5 Comments

Thank u for your fast help. It works :)
Consider accepting the answer if it works.
U where to fast I will as soon I can :)
Edited the answer to remove the redundant try/catch block. The try/catch block has no effect, though, as it just reraises every exception - it would work the same without it.
In a example code I had it was done that way so I thought it was better to do so thanks for correcting it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.