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)這是我的代碼,讓機(jī)器人等待對msg. 但是,由于某種原因,當(dāng)我msg同時有兩條(消息)等待反應(yīng)時,當(dāng)我對一條消息作出反應(yīng)時,即使我沒有對第二條消息做出反應(yīng),都會觸發(fā)成功。這對于基于管理員的審批系統(tǒng)來說是個大問題……有誰知道為什么會這樣或如何解決?
1 回答

蕪湖不蕪
TA貢獻(xiàn)1796條經(jīng)驗 獲得超7個贊
這段代碼真的很亂,但是如果你正在尋找一種只等待對一條消息的反應(yīng)的方法,你應(yīng)該在你的檢查命令中添加一些東西,例如:
@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)}")
添加回答
舉報
0/150
提交
取消