【问题标题】:How to send a message and collect reactions from it in Discord.py如何在 Discord.py 中发送消息并从中收集反应
【发布时间】:2020-05-07 12:35:36
【问题描述】:

如果机器人要发送消息

            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 秒后将反应加起来?

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

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

    【讨论】:

    • 我收到Vote Result: 0 positive and 0 negative reactions,即使反应不是 0。
    • @ZacIsa 哦,我明白了,我忘了你必须重新获取消息!现在应该修复了
    猜你喜欢
    • 2019-12-18
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 1970-01-01
    • 2020-10-01
    相关资源
    最近更新 更多