Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 反应编辑,仅编辑discord.py中最近的命令_Python_Python 3.x_Discord_Discord.py_Discord.py Rewrite - Fatal编程技术网

Python 反应编辑,仅编辑discord.py中最近的命令

Python 反应编辑,仅编辑discord.py中最近的命令,python,python-3.x,discord,discord.py,discord.py-rewrite,Python,Python 3.x,Discord,Discord.py,Discord.py Rewrite,这大部分都很好,但如何使其仅编辑用户发送的最新消息?如果有人键入同一命令两次,然后对第二条消息作出反应,它将编辑这两条消息,只要它在超时前的60秒窗口中。代码如下: px = await ctx.send(embed=e) for name in reactions: emoji = get(ctx.guild.emojis, name=name) try: await px.add_reaction(emoji o

这大部分都很好,但如何使其仅编辑用户发送的最新消息?如果有人键入同一命令两次,然后对第二条消息作出反应,它将编辑这两条消息,只要它在超时前的60秒窗口中。代码如下:

        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

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

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

px.id == reaction.message.id
Px应该是具有ID的消息对象


这将确保当他们单击嵌入上的某个反应时,正确的处理程序会收到该反应。你说你只想要最新的来处理它。。。这不太可能做到这一点。但是,对最新事件的任何反应都将针对最新事件进行处理,而对较早事件的任何反应都将由较早的处理者进行处理。如果这有道理的话。

哦,这是有道理的,是的,这基本上就是我想要的。只是措辞怪异,但谢谢你!