【发布时间】:2020-03-31 06:14:53
【问题描述】:
这是我第一次在这里提问,所以我可能会在某些方面搞砸。
所以我有一个经济机器人,我希望这个命令有 3 个反应,这样人们就可以告诉它该做什么。在这里,这是为了收钱,提升收入或提升他们“公司”的最大产能。
阅读API文档后,我首先有3个检查函数来检查每个反应,比如这个:
(stuff)
message = await ctx.send(embed=embed)
await message.add_reaction("1️⃣")
await message.add_reaction("2️⃣")
await message.add_reaction("3️⃣")
def check1(reaction, user):
return user == ctx.message.author and str(reaction.emoji) == "1️⃣"
try:
reaction, user = await client.wait_for("reaction_add", timeout = 30.0, check = check1)
except asyncio.TimeoutError:
print("Timeout")
else:
(code to collect money)
但后来我意识到它会一个一个地检查这些,所以你必须等待第一个超时,然后它才会检查第二个。所以经过一番思考,我想出了这个:
(stuff)
message = await ctx.send(embed=embed)
await message.add_reaction("1️⃣")
await message.add_reaction("2️⃣")
await message.add_reaction("3️⃣")
def check(reaction, user):
return user == ctx.message.author and user != "Robofriend#7565" and str(reaction.emoji) == "1️⃣" or "2️⃣" or "3️⃣"
try:
reaction, user = await client.wait_for("reaction_add", timeout = 30.0, check = check)
except asyncio.TimeoutError:
print("Timeout")
else:
if str(reaction.emoji) == "1️⃣":
(code to collect money)
我惊讶地发现这已经在堆栈溢出中以与我相同的方式得到了回答,但由于某种原因,我的有问题。当我运行命令时,检查会立即返回 True,因为它会检查自己的反应......我知道这一点是因为我通过使其在检查功能上打印用户来检查。
任何帮助表示赞赏!
【问题讨论】:
标签: python discord discord.py