How to send a message and collect reactions from it in Discord.py

痴心易碎 提交于 2021-01-29 12:16:50

问题


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) + '**')
            await vote_msg.add_reaction('✅')
            await vote_msg.add_reaction('❎')

How could I get the bot to add up the reactions after 30 seconds?


回答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')


来源:https://stackoverflow.com/questions/59841280/how-to-send-a-message-and-collect-reactions-from-it-in-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!