首页 > 解决方案 > discord.py 更改嵌入页面将更改所有嵌入中的页面

问题描述

如果我键入命令两次并尝试在一个嵌入中更改页面,它将更改两个嵌入中的页面。如果我键入不同的命令,也会发生这种情况,它总是会更改所有嵌入页面上的页面。我该如何解决这个问题?

            msg = await ctx.send(embed=pages[current].set_footer(text=f"{current+1}/{len(pages)}"))
            
            for button in buttons:
                await msg.add_reaction(button)
                
            while True:
                try:
                    reaction, user = await self.client.wait_for("reaction_add", check=lambda reaction, user: user == ctx.author and reaction.emoji in buttons, timeout=30.0)

                except asyncio.TimeoutError:
                    pass

                else:
                    previous_page = current
                    if reaction.emoji == u"\u23EA":
                        current = 0
                        
                    elif reaction.emoji == u"\u2B05":
                        if current > 0:
                            current -= 1
                            
                    elif reaction.emoji == u"\u27A1":
                        if current < len(pages)-1:
                            current += 1

                    elif reaction.emoji == u"\u23E9":
                        current = len(pages)-1

                    for button in buttons:
                        await msg.remove_reaction(button, ctx.author)

                    if current != previous_page:
                        await msg.edit(embed=pages[current].set_footer(text=f"{current+1}/{len(pages)}"))

标签: python-3.xdiscord.py

解决方案


很简单,如果作者是命令作者并且表情符号是正确的表情符号,则您的检查函数会返回,如果我们希望检查仅针对该消息返回 true,我们还需要检查消息 ID。你的支票应该是,

check=lambda reaction, user: user == ctx.author and reaction.emoji in buttons and reaction.message.id == msg.id

msg您发送并添加反应的消息在哪里。

参考:


推荐阅读