(discord.py) wait_for 函数不检查作者是否对消息作出反应
(discord.py) wait_for function not checking if author reacted to message
我正在为我的派系机器人创建一个“删除派系”命令,它要求用户确认他们想要使用反应删除他们的派系。我的代码如下:
embed = discord.Embed(
title=":warning: Are you sure?",
colour=discord.Colour.purple(),
description=f"Are you sure you want to delete **{name_capital}**? "
f"*Your members will lose their roles and so will you.*"
)
txt = await ctx.send(embed=embed)
await txt.add_reaction("✅")
await txt.add_reaction("❌")
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) == "✅" or "❌"
try:
reaction, user = await self.client.wait_for('reaction_add', timeout=8.0, check=check)
except asyncio.TimeoutError:
embed = discord.Embed(
title=":x: Deletion cancelled",
colour=discord.Colour.purple(),
description="Message timed out"
)
await txt.delete()
await ctx.send(embed=embed)
else:
if reaction.emoji == "❌":
await txt.delete()
elif reaction.emoji == "✅":
pass # delete faction code
该命令在大多数情况下都有效。但是,它也适用于对消息做出反应的其他用户,尽管我在检查功能中声明不会发生这种情况。
出了什么问题,我该如何解决?
只是猜测,但您的检查函数可能格式不正确。应该是这样的:
def check(reaction, user):
return user == ctx.author and (str(reaction.emoji) == "✅" or "❌")
我正在为我的派系机器人创建一个“删除派系”命令,它要求用户确认他们想要使用反应删除他们的派系。我的代码如下:
embed = discord.Embed(
title=":warning: Are you sure?",
colour=discord.Colour.purple(),
description=f"Are you sure you want to delete **{name_capital}**? "
f"*Your members will lose their roles and so will you.*"
)
txt = await ctx.send(embed=embed)
await txt.add_reaction("✅")
await txt.add_reaction("❌")
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) == "✅" or "❌"
try:
reaction, user = await self.client.wait_for('reaction_add', timeout=8.0, check=check)
except asyncio.TimeoutError:
embed = discord.Embed(
title=":x: Deletion cancelled",
colour=discord.Colour.purple(),
description="Message timed out"
)
await txt.delete()
await ctx.send(embed=embed)
else:
if reaction.emoji == "❌":
await txt.delete()
elif reaction.emoji == "✅":
pass # delete faction code
该命令在大多数情况下都有效。但是,它也适用于对消息做出反应的其他用户,尽管我在检查功能中声明不会发生这种情况。
出了什么问题,我该如何解决?
只是猜测,但您的检查函数可能格式不正确。应该是这样的:
def check(reaction, user):
return user == ctx.author and (str(reaction.emoji) == "✅" or "❌")