python-3.x - 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)}"))
解决方案
很简单,如果作者是命令作者并且表情符号是正确的表情符号,则您的检查函数会返回,如果我们希望检查仅针对该消息返回 true,我们还需要检查消息 ID。你的支票应该是,
check=lambda reaction, user: user == ctx.author and reaction.emoji in buttons and reaction.message.id == msg.id
msg
您发送并添加反应的消息在哪里。
参考:
推荐阅读
- javascript - 将按升序排序的日期数组合并到日期范围数组中
- python - 为什么我的准系统 C/C++ 模型不能像 TensorFlow 一样执行?
- reactjs - React Native 项目无法运行
- javascript - Webpack WordPress 图片下划线上传文件夹
- angular - 在页面重新加载之间保存角度应用程序的状态
- instagram - 为什么 Spark AR 中的 FixedTargetTracking 不适用于彩色徽标?
- db2 - 为什么我的查询因 SQLCODE=-204 而失败?
- python - 拆分单元格上的值并使用 Python 使用拆分值逐行更新新列
- javascript - 如何使用 MediaRecorder 作为 MediaSource
- java - 从android中的micro SD卡读取文件