亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何讓機器人只響應同一消息的 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 關注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號