[英]How do I get my bot to respond only to reactions on a specific message? | discord.py
我正在尝试为朋友实现一个机器人,其中“info”命令将在一个嵌入页面上显示用户的信息,下一个将显示用户拥有的任何字符(通过 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.