【发布时间】:2020-12-01 15:25:50
【问题描述】:
我正在尝试为朋友实现一个机器人,其中“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 替换为用户的最新消息,但这返回了相同的问题。任何帮助将不胜感激!
【问题讨论】:
标签: python python-3.x discord.py discord.py-rewrite