Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a list of users reacted to message discord.py rewrite

I'm trying to make a command for a bot that when everybody that have been mentioned in the message reacts to the bot's response, it mentions the original message author

That's what i tried

        if msg.content.startswith('/iniciar'):
            async with msg.channel.typing():
                mentions = ""
                for mention in msg.mentions:
                    mentions = mentions + " " + mention.mention
                bot_msg: discord.Message = await msg.channel.send(mentions + ' confirmem presença reagindo abaixo.')
                await bot_msg.add_reaction('✅')
                for mention in msg.mentions:
                    def check(reaction, user):
                        return user == mention and str(reaction.emoji) == '✅'
                    try:
                        reaction, user = await client.wait_for('reaction_add', check=check)
                    finally:
                        reactionusers: list = await reaction.users().flatten()
                        reactionusers.remove(reactionusers[0])
                        print(reactionusers)
                        print(msg.mentions)
                        if reactionusers == msg.mentions:
                            await msg.channel.send(msg.author.mention)
                        else:
                            return

like image 926
Sxigames Gameplay Avatar asked Feb 01 '26 18:02

Sxigames Gameplay


1 Answers

Okay well first off, you'll need to consider a few things in this current implementation. For one, you'll probably want to save the message ID that you want the bot to watch somewhere. Whether this is SQL, a Shelve, whatever

For this, when the /iniciar function is called, save the message ID in whatever preferred long-term storage method you prefer, somewhere the bot can check.

Then you'll want to consider how you're activating this codeblock, which I can't see in your current given code. I'd suggest, for your purposes, using on_reaction_add which has documentation here: https://discordpy.readthedocs.io/en/latest/api.html#discord.on_reaction_add

Use Reaction.message to grab the message object, and read the relevant information for who is mentioned in the message into a list (similar to how you're doing).

When a user reacts to the message and on_reaction_add is called:

  1. Check if the message being reacted to is in your storage solution, if it's a message you're waiting to see a reaction on the continue
  2. Then check if the user who reacted is in the list of mentioned users in that message
  3. If they are, then have the bot mention the message author
  4. Finally check if all the users have reacted, if so, remove the message from that SQL/Shelve/whatever storage you had it in so no further reactions will mention the author.
like image 127
J0hn Avatar answered Feb 03 '26 09:02

J0hn