如何在Discord.py中发送消息并收集消息

时间:2020-01-21 12:34:02

标签: python discord discord.py

如果机器人要发送消息

            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('❎')

如何让机器人在30秒后汇总反应?

1 个答案:

答案 0 :(得分:0)

使用message.reactionsDocumentation

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