为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

喵喔喔 2023-06-13 10:37:39
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同时有两条(消息)等待反应时,当我对一条消息作出反应时,即使我没有对第二条消息做出反应,都会触发成功。这对于基于管理员的审批系统来说是个大问题……有谁知道为什么会这样或如何解决?
查看完整描述

1 回答

?
芜湖不芜

TA贡献1796条经验 获得超7个赞

这段代码真的很乱,但是如果你正在寻找一种只等待对一条消息的反应的方法,你应该在你的检查命令中添加一些东西,例如:


@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)}")


查看完整回答
反对 回复 2023-06-13
  • 1 回答
  • 0 关注
  • 75 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信