if user == and str(reaction.emoji) == "U0001F5BCU0000FE0F":
channel = client.get_channel(1245390045859549285) #👜-reward-container
# Filter out mention at the start
mention_regex = re.compile(r"^<@&(d+)> ")
filtered_content = mention_regex.sub("", reaction.message.content, 1)
print(filtered_content)
message = await channel.send(f"{filtered_content} by {reaction.message.author.mention}")
await message.add_reaction("U0001F5BCU0000FE0F")
Trying to find a way to prevent people from adding this reaction before adding U00002620U0000fe0f first. I came up with this:
elif reaction.emoji == 'U0001F5BCU0000FE0F':
skull_reaction = discord.utils.get(reaction.message.reactions, emoji='U00002620U0000fe0f')
is_skull_user = False
async for skull_user in skull_reaction.users():
if skull_user == user:
is_skull_user = True
break
if not is_skull_user:
await reaction.remove(user)
But that doesn’t really work – Bot still adds its own message and when someone adds later on ‘U00002620U0000fe0f’ nothing happens. Can someone help me with this?
Ive tried putting the 2nd part into the code but it doesn’t do what I want – reaction is being removed but bot still adds reaction and then nothing happens
Rivendare is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have fixed this issue myself. Instead of making async for skull_user in skull_reaction_users() I’ve made variable for “if no skull_reaction”. It looks like this:
if user == reaction.message.author and str(reaction.emoji) == "U0001F5BCU0000FE0F":
channel = client.get_channel(1245390045859549285) #👜-reward-container
picture_reaction = discord.utils.get(reaction.message.reactions, emoji='U0001F5BCU0000FE0F')
skull_reaction = discord.utils.get(reaction.message.reactions, emoji='U00002620U0000fe0f')
print("2")
if not skull_reaction:
print("3")
await picture_reaction.remove(user)
return
Then the rest of the code.
I’m not familiar with discord py, but it seems like the emoji class can’t be compared to a string, try adding an str like you did previously, ie elif str(reaction.emoji) == 'U0001F5BCU0000FE0F':
.
Hopefully that can fix our issue.
Also, according to the doc, the last part can be simplified into :
elif str(reaction.emoji) == 'U0001F5BCU0000FE0F':
skull_reaction = discord.utils.get(reaction.message.reactions, emoji='U00002620U0000fe0f')
# Flatten the async iterator into a list
users = [user async for user in skull_reaction.users()]
# Check if the user is in the list of users who reacted
if user not in users:
await reaction.remove(user)
Hope that helps !
1