discord.py:bot.wait_forr()截取message.add_reaction()并一次性工作



我有一个不协调.py.的问题

我想做这样的事情:

msg = await ctx.author.send('message')
await msg.add_reaction('✅')
await msg.add_reaction('❎')
def check(reaction, user):
return user != bot.user and reaction.message.id == choice.id and reaction.emoji in ['✅', '❎']
r, u = await bot.wait_for('reaction_add', check=check)
result = r.emoji == '✅'

但它不起作用,当我尝试这个:

def check(reaction, user):
print(user.name)
return user != bot.user and reaction.message.id == choice.id and reaction.emoji in ['✅', '❎']

我在控制台中有机器人的名称,当我试图点击一个反应时,没有打印任何内容,所以我认为bot.wait_for()一次有效吗?

我希望你能理解。谢谢你抽出时间。

在您的检查中,您有reaction.message.id == choice.id,我不确定choice是什么。这应该有效:

message = await ctx.author.send("message")
await message.add_reaction("✅")
await message.add_reaction("❎")
def check(reaction, user):
return user == ctx.author and reaction.message == message and reaction.emoji in ["✅", "❎"]
response = await client.wait_for("reaction_add", check=check)
result = response[0].emoji == "✅"

最新更新