如何让我的机器人只对特定消息的反应做出响应?|不和谐.py



我正试图为一个朋友实现一个机器人程序;信息";命令将在一个嵌入页面上显示用户的信息,下一个将显示用户拥有的任何字符(通过gspread读取(。

mx = await ctx.send(embed=contents[0])   
await mx.add_reaction("◀")
await mx.add_reaction("▶")
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["◀", "▶"]
while True:
try:
reaction, user = await client.wait_for("reaction_add", timeout=20, check=check)
if str(reaction.emoji) == "▶" and cur_page != pages:
cur_page += 1
await mx.edit(embed=contents[cur_page - 1])
await mx.remove_reaction(reaction, user)
elif str(reaction.emoji) == "◀" and cur_page > 1:
cur_page -= 1
await mx.edit(embed=contents[cur_page - 1])
await mx.remove_reaction(reaction, user)
else:
await mx.remove_reaction(reaction, user)
except asyncio.TimeoutError:
await mx.clear_reaction("◀")
await mx.clear_reaction("▶")
break 

问题是,每当用户发送多个信息命令时,在做出反应时,就会导致他们所有仍处于活动状态的消息都被编辑,而不仅仅是他们正在做出反应的消息。我也尝试过:

def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["◀", "▶"]
mx == reaction.message

但它并没有解决问题。我还尝试了.json转储并用用户的最新消息替换mx.id,但这返回了相同的问题。任何帮助都将不胜感激!

mx == reaction.message也应该是return语句的一部分。

固定代码:

def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["◀", "▶"] and mx == reaction.message

最新更新