【问题标题】:Reaction edit, only edit the most recent command in discord.py反应编辑,只编辑discord.py中最新的命令
【发布时间】:2020-11-26 19:34:55
【问题描述】:

大部分都很好,但我如何让它只编辑用户发送的最新消息?如果有人键入相同的命令两次,然后对第二条消息做出反应,只要它在超时之前的 60 秒窗口中,它就会编辑 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

我只希望它编辑该用户最近使用的命令。谢谢。

【问题讨论】:

    标签: python python-3.x discord discord.py discord.py-rewrite


    【解决方案1】:

    在我的手机上很难打字。但是在检查中添加

    px.id == reaction.message.id
    

    Px 应该是一个带有 ID 的消息对象

    这将确保当他们单击嵌入上的反应时,正确的处理程序会收到它。你说你只想要最新的来处理它......这不会完全做到这一点。但是对最新的任何反应都将针对最新的进行处理,而对较早的任何反应都将由较早的处理程序处理。如果这有意义的话。

    【讨论】:

    • 哦,这是有道理的,是的,这基本上就是我想要的。只是措辞奇怪,但谢谢!
    猜你喜欢
    • 2020-10-29
    • 2019-12-12
    • 2021-04-21
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多