Reputation: 23
@client.event
async def on_raw_reaction_add(payload):
if payload.emoji.name == '❌':
#code
elif payload.emoji.name == '✅':
#code
When someone reacts with an x it runs the code but when he reacts with a tick after reacting with the x it also runs the code under the tick is there a way of disabling reactions after someone has already reacted?
Upvotes: 0
Views: 395
Reputation: 2054
Here's how I did that:
@client.event
async def on_reaction_add(reaction, user):
# Checks reactions only in the logchannel
if reaction.message.channel.id != logchannel.id:
return
total_reactions = 0
for r in reaction.message.reactions:
total_reactions += r.count
member = reaction.message.mentions[0]
if total_reactions == 3:
if reaction.emoji == "✅":
# Stuff
elif reaction.emoji == "❌":
# Stuff
elif total_reactions > 3:
await reaction.remove(user)
My goal with this code is to make it so that there are 2 bot reactions and 1 user reaction at all times.
I first count the total reactions on the message by iterating through the message's reactions.
Then, if there are more than 3 reactions (meaning the user has reacted more than once), I don't execute any of the code and instead immediately remove that user's reaction.
This makes it so that after you react to 1 emoji, it's impossible to react to the other, and no other user can react as well.
Hope this helps!
Upvotes: 0
Reputation: 1439
Store the payload.user_id in a data structure, add the user_id to the structure and make sure to check if the payload.user_id is not in the structure before running the code.
Upvotes: 1