首页 > 解决方案 > Discord.py - 在有人第一次做出反应后检查反应

问题描述


vote_msg = await ctx.send(embed=embed)
    await vote_msg.add_reaction('✅')
    await vote_msg.add_reaction('❎')
    reaction, member = await ctx.bot.wait_for('reaction_add')
    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
        elif reaction.emoji == '❎':
            negative = reaction.count - 1
    print(positive)
    print(negative)

目前我有这个来重新获取对消息的反应,我怎样才能让它在有人第一次反应后重新获取它,而不是让它等待 5 秒并检查?

标签: pythonpython-3.xdiscorddiscord.pydiscord.py-rewrite

解决方案


我认为您正在寻找on_reaction 侦听器

您可以从 react.message.reactions 访问所有消息反应,如下所示:

@bot.event
async def on_reaction_add(reaction, user):
    reactions = reaction.message.reactions
    # DO WHAT YOU WANT HERE
    

推荐阅读