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.
CodePudding user response:
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)