反应编辑,仅编辑 discord.py 中最近的命令
Reaction edit, only edit the most recent command in discord.py
大部分都可以,但是如何让它只编辑用户最近发送的消息?如果有人两次键入相同的命令,然后对第二条消息做出反应,只要在超时前的 60 秒 window 内,它将编辑 both 条消息。这是代码:
px = await ctx.send(embed=e)
for name in reactions:
emoji = get(ctx.guild.emojis, name=name)
try: await px.add_reaction(emoji or name)
except: return
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in reactions
while True:
try:
reaction, user = await self.bot.wait_for("reaction_add", timeout=60, check=check)
if str(reaction.emoji) == "right":
p += 1
# doing the command again but + 1 page
await px.edit(embed=e)
elif str(reaction.emoji) == "left":
p -= 1
# doing the command again but - 1 page
await px.edit(embed=e)
else:
await px.remove_reaction(reaction, user)
except asyncio.TimeoutError:
break
我只希望它编辑该用户最近使用的命令。谢谢
我的 phone 好难打字。但是在检查中添加
px.id == reaction.message.id
Px 应该是具有 ID
的消息对象
这将确保当他们点击嵌入的反应时,正确的处理程序会收到它。你说你只想要最新的来处理它......这不会完全做到这一点。但是对最新的任何反应都将由最新的处理程序处理,而对较早的反应的任何反应都将由较早的处理程序处理。如果说得通。
大部分都可以,但是如何让它只编辑用户最近发送的消息?如果有人两次键入相同的命令,然后对第二条消息做出反应,只要在超时前的 60 秒 window 内,它将编辑 both 条消息。这是代码:
px = await ctx.send(embed=e)
for name in reactions:
emoji = get(ctx.guild.emojis, name=name)
try: await px.add_reaction(emoji or name)
except: return
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in reactions
while True:
try:
reaction, user = await self.bot.wait_for("reaction_add", timeout=60, check=check)
if str(reaction.emoji) == "right":
p += 1
# doing the command again but + 1 page
await px.edit(embed=e)
elif str(reaction.emoji) == "left":
p -= 1
# doing the command again but - 1 page
await px.edit(embed=e)
else:
await px.remove_reaction(reaction, user)
except asyncio.TimeoutError:
break
我只希望它编辑该用户最近使用的命令。谢谢
我的 phone 好难打字。但是在检查中添加
px.id == reaction.message.id
Px 应该是具有 ID
的消息对象这将确保当他们点击嵌入的反应时,正确的处理程序会收到它。你说你只想要最新的来处理它......这不会完全做到这一点。但是对最新的任何反应都将由最新的处理程序处理,而对较早的反应的任何反应都将由较早的处理程序处理。如果说得通。