如何让机器人只响应同一消息的 add_reaction?

def isAdmin(reaction, user):

    for i in admins:

        if user.id == i: return (str(reaction.emoji) == '👍' or str(reaction.emoji) == '👎')

try: reaction, user = await self.bot.wait_for('reaction_add', timeout=43200, check=isAdmin)

except asyncio.TimeoutError: await msg.edit(embed=embedEnd)

else:

    resign_channel = discord.utils.get(ctx.guild.channels, name="resignings") 

    if str(reaction.emoji) == '👍':

        print('{}: {} resigned {} {}.'.format(extCalls.timeNow('datetime'), ctx.channel.category.name, firstName, lastName))

        await msg.edit(embed=embedFin)

        await resign_channel.send(embed=embedConf)

    else: await msg.edit(embed=embedEnd)

这是我的代码,让机器人等待对msg. 但是,由于某种原因,当我msg同时有两条(消息)等待反应时,当我对一条消息作出反应时,即使我没有对第二条消息做出反应,都会触发成功。这对于基于管理员的审批系统来说是个大问题……有谁知道为什么会这样或如何解决?


喵喔喔
浏览 108回答 1
1回答

芜湖不芜

这段代码真的很乱,但是如果你正在寻找一种只等待对一条消息的反应的方法,你应该在你的检查命令中添加一些东西,例如:@bot.command(name="some_command")async def sc(ctx):    msg = await ctx.send("Some interesting message!")    def check(reaction, user):        return reaction.message.id == msg.id    try:        reaction, user = await bot.wait_for("reaction_add", check=check,timeout=30.0)    except asyncio.TimeoutError:        await ctx.send("timeout")        return    await ctx.send(f"You reacted {str(reaction)}")
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python