如何让我的机器人只响应对特定消息的反应? | discord.py
How do I get my bot to respond only to reactions on a specific message? | discord.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
我正在尝试为朋友实现一个机器人,其中“信息”命令将在一个嵌入页面上显示用户的信息,而下一个将显示用户拥有的任何字符(通过 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