【发布时间】:2021-04-23 06:24:30
【问题描述】:
我有一个嵌入得到多个反应的事件。在这里,用户有 x 秒的时间来选择反应。如果这是“错误的”,则应该吐出一个错误。如果反应是我定义的所需反应,则应出现另一条消息。我有这个代码,但我无法进一步了解:
await embedX.add_reaction("1️⃣")
await embedX.add_reaction("2️⃣")
await embedX.add_reaction("3️⃣")
try:
reaction = await self.bot.wait_for('reaction_add', timeout=10)
if str(reaction.emoji) == "1️⃣":
await ctx.send("Congrats, right answer.")
else:
await ctx.send("Incorrect reaction.")
except asyncio.TimeoutError:
await ctx.send("Took too long.")
错误:
AttributeError: 'tuple' object has no attribute 'emoji'.
我对 Python 还是很陌生,所以我希望在这里找到帮助。
得到帮助后,我的代码现在如下所示:
e = discord.Embed(color=discord.Color.gold())
e.title = "Woah, look!"
e.description = "**Does this work?**"
e.add_field(name="1️⃣", value="Yes", inline=False)
e.add_field(name="2️⃣", value="No", inline=False)
e.add_field(name="3️⃣", value="Maybe", inline=False)
e.set_footer(text="You have 10 seconds to answer the question", icon_url=self.bot.user.avatar_url)
e.timestamp = datetime.datetime.utcnow()
embedX = await ctx.send(embed=e)
await embedX.add_reaction("1️⃣")
await embedX.add_reaction("2️⃣")
await embedX.add_reaction("3️⃣")
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=10)
if user == self.bot.user:
return
if str(reaction.emoji) == "1️⃣":
await embedX.edit(embed=er)
else:
await ctx.send(embed=ew)
except asyncio.TimeoutError:
await embedX.edit(embed=etl)
有时机器人会计算反应,只是1 - 对其他人他没有反应,但他没有做的是:如果反应错误,则放弃/编辑嵌入。
(er 和 ew 实际上是我之前定义的其他嵌入。)
【问题讨论】:
标签: python discord discord.py