【发布时间】:2020-06-27 05:50:09
【问题描述】:
试图让我的机器人处理对消息的多个反应。
如果我只检查一个反应,我可以得到一个这样的版本:
reaction, user = await bot.wait_for('reaction_add', timeout=5, check=checkR)
但是当我检查多个反应(如纸和剪刀)时,代码根本不起作用。
我到处寻找有关此方面的帮助,但找不到任何在 Discord 重写后的内容。
任何帮助表示赞赏!
# test rps
@bot.command()
async def test(ctx):
eb = await getEmbed(ctx, "Rock, Paper, Scissors", "", {}, "", "Choose one:", discord.Colour.gold())
msg = await ctx.message.channel.send(embed = eb)
channel = msg.channel
for emoji in ('????', '????', "✂"):
await msg.add_reaction(emoji)
# now check for response
def checkR(reaction, user):
return user == ctx.message.author and str(reaction.emoji) == '????'
def checkP(reaction, user):
print("in paper")
return user == ctx.message.author and str(reaction.emoji) == '????'
def checkS(reaction, user):
return user == ctx.message.author and str(reaction.emoji) == '✂'
try:
reaction, user = await bot.wait_for('reaction_add', timeout=5, check=checkR)
reaction, user = await bot.wait_for('reaction_add', timeout=5, check=checkP)
reaction, user = await bot.wait_for('reaction_add', timeout=5, check=checkS)
except asyncio.TimeoutError:
await embed(ctx, "Game timed out.")
return
else:
# we got a reaction
await embed(ctx, "GOT A REACTION")
await discord.Message.delete(msg)
pass
【问题讨论】: