Skip to content Skip to sidebar Skip to footer

How To Send A Message And Collect Reactions From It In Discord.py

If a bot was to send a message vote_msg = await ctx.channel.send('Vote ' + '@' + str(member) + ' out of the server? **' + str(out) + '/' + str(of) + '**') a

Solution 1:

Use message.reactions: Documentation

            vote_msg = await ctx.channel.send('Vote ' + '@' + str(member) + ' out of the server? **' + str(out) + '/' + str(of) + '**')
            await vote_msg.add_reaction('✅')
            await vote_msg.add_reaction('❎')
            await asyncio.sleep(30) # wait 30 seconds with the asyncio module (import asyncio if you haven't already)
            vote_msg = await vote_msg.channel.fetch_message(vote_msg.id) # refetch message
            # default values
            positive = 0
            negative = 0
            for reaction in vote_msg.reactions:
                if reaction.emoji == '✅':
                    positive = reaction.count - 1 # compensate for the bot adding the first reaction
                if reaction.emoji == '❎':
                    negative = reaction.count - 1

            print(f'Vote Result: {positive} positive and {negative} negative reactions')

Post a Comment for "How To Send A Message And Collect Reactions From It In Discord.py"