簡體   English   中英

如何在 Discord.py 中發送消息並從中收集反應

[英]How to send a message and collect reactions from it in 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 秒后把反應加起來?

使用message.reactions文檔

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM