我正在寻找一个命令,如果message.author标记用户,机器人将对消息做出两次反应,然后等待被标记的用户选择一个或另一个选择的反应。现在一切正常,除非用户对一个或另一个表情符号作出反应,它什么都不做。当他们对两个表情符号做出反应时,它会发送reaction
的消息。
if message.content.lower().startswith('!marry'):
user = message.mentions[0]
if message.author == user:
await client.send_message(message.channel, "{} you can't marry yourself dummy 😒".format(message.author.mention))
else:
if get_spouse(message.author) != "No One":
await client.send_message(message.channel, "{}, you're already married to {} 😒".format(message.author.mention, get_spouse(message.author)))
else:
if (get_spouse(user)) != "No One":
await client.send_message(message.channel, "{} is already married. Get your own spouse. 😒".format(user.mention))
else:
marriagemsg = await client.send_message(message.channel, "{} *has proposed to* {} 💍".format(message.author.mention, user.mention))
await client.add_reaction(marriagemsg, "✅")
await client.add_reaction(marriagemsg, "❌")
while True:
reaction = await client.wait_for_reaction(emoji="✅", message=marriagemsg,
check=lambda reaction, user: user == message.mentions[0])
reaction2 = await client.wait_for_reaction(emoji="❌", message=marriagemsg,
check=lambda reaction, user: user == message.mentions[0])
if reaction:
await client.send_message(message.channel, "{} **is now married to** {} 🤵👰".format(message.author.mention, reaction.user.mention))
add_spouse(message.author, user.name)
add_spouse(reaction.user, message.author.name)
else:
if reaction2:
await client.send_message(message.channel, "{} **rejects** {}**'s proposal** ✋🙄".format(reaction2.user.mention, message.author.mention))
您正在使用的多个wait_for_reaction
检查导致了此问题。机器人将等到用户对marriagemsg
上的react作出反应,然后检查用户是否对react作出反应。
而不是使用多个wait_for_reaction
检查,只需使用一个并在列表中填充您的表情符号。您也可以使用elif
而不是else: if
。
if message.content.lower().startswith('!marry'):
user = message.mentions[0]
if message.author == user:
await client.send_message(message.channel, "{} you can't marry yourself dummy 😒".format(message.author.mention))
else:
if get_spouse(message.author) != "No One":
await client.send_message(message.channel, "{}, you're already married to {} 😒".format(message.author.mention, get_spouse(message.author)))
else:
if (get_spouse(user)) != "No One":
await client.send_message(message.channel, "{} is already married. Get your own spouse. 😒".format(user.mention))
else:
marriagemsg = await client.send_message(message.channel, "{} *has proposed to* {} 💍".format(message.author.mention, user.mention))
await client.add_reaction(marriagemsg, "✅")
await client.add_reaction(marriagemsg, "❌")
answer = await client.wait_for_reaction(emoji=["✅", "❌"], message=marriagemsg,
check=lambda reaction, user: user == message.mentions[0])
if answer.reaction.emoji == "✅":
await client.send_message(message.channel, "{} **is now married to** {} 🤵👰".format(message.author.mention, answer.user.mention))
add_spouse(message.author, user.name)
add_spouse(answer.user, message.author.name)
elif answer.reaction.emoji == "❌":
await client.send_message(message.channel, "{} **rejects** {}**'s proposal** ✋🙄".format(answer.user.mention, message.author.mention))