【发布时间】:2021-11-04 03:42:48
【问题描述】:
所以我编写了这段代码,一旦用户对某些表情符号做出反应,它就会发送嵌入并更改其值/项目。它适用于单个嵌入,但是当用户要求像您在图像中看到的相同的多个嵌入时,对嵌入的反应也会改变其他类似嵌入的值。
代码部分
@client.command()
async def embed(ctx):
current = 1
embed = discord.Embed(title = f'{current}')
buttons = [ u"\u25C0", u"\u25FC" , u"\u25B6" , u"\U0001F5D1"]
msg = await ctx.send(embed = embed)
for button in buttons:
await msg.add_reaction(button)
while True:
try:
reaction , user = await client.wait_for("reaction_add", check = lambda reaction,user: user == ctx.author and reaction.emoji in buttons, timeout = 180.0)
except asyncio.TimeoutError:
embed.set_footer(text= "Timeout.")
await msg.clear_reactions()
else:
previous_page = current
if reaction.emoji == u"\u25C0":
current -= 1
embed.add_field(name = None, value = f'{current}')
elif reaction.emoji == u"\u25FC":
if current > 0:
current = 0
embed.add_field(name = None, value = f'{current}')
elif reaction.emoji == u"\u25B6":
current += 1
embed.add_field(name = None, value = f'{current}')
elif reaction.emoji == u"\U0001F5D1":
await msg.edit(embed = embed)
await msg.clear_reactions()
for button in buttons:
await msg.remove_reaction(button, ctx.author)
if current != previous_page:
embed.add_field(name = None, value = f'{current}')
await msg.edit(embed = embed)
图片:https://imgur.com/a/fEpz9jD
注意:我在机器人中使用的代码与这个完全相同。我没有包括那些嵌入的截图和截图,因为它被用于 NSFW 目的/图像。
谢谢。
【问题讨论】:
-
也许看看你的代码,问问自己为什么会这样。在您的
while True-loop 中,您不断检查条件是否已给出。虽然这是真的,但如果可能,机器人将始终编辑现有的嵌入。 -
你能告诉我应该怎么做吗?
标签: discord.py