Search code examples
pythondiscord.py

Bot allow reaction Y only if reaction X has been added


    if user ==  and str(reaction.emoji) == "\U0001F5BC\U0000FE0F":
        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("\U0001F5BC\U0000FE0F")

Trying to find a way to prevent people from adding this reaction before adding \U00002620\U0000fe0f first. I came up with this:

elif reaction.emoji == '\U0001F5BC\U0000FE0F':
  skull_reaction = discord.utils.get(reaction.message.reactions, emoji='\U00002620\U0000fe0f')
  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 '\U00002620\U0000fe0f' 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


Solution

  • 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) == "\U0001F5BC\U0000FE0F":
        channel = client.get_channel(1245390045859549285) #👜-reward-container
        picture_reaction = discord.utils.get(reaction.message.reactions, emoji='\U0001F5BC\U0000FE0F')
        skull_reaction = discord.utils.get(reaction.message.reactions, emoji='\U00002620\U0000fe0f')
        print("2")
    
        if not skull_reaction:
            print("3")
            await picture_reaction.remove(user)
            return
    

    Then the rest of the code.