问题
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