.verify 命令未赋予角色(discord.py 1.7.3)
Posted
技术标签:
【中文标题】.verify 命令未赋予角色(discord.py 1.7.3)【英文标题】:.verify command not giving role (discord.py 1.7.3) 【发布时间】:2022-01-10 14:59:14 【问题描述】:我正在创建一个不和谐的机器人,我想用这个机器人创建一个验证命令。我开始研究它,一切正常到给出反应的地步(发送带有“是”和“否”反应的消息),当我运行代码时,它不会抛出任何错误。如果你帮助我,我还想解释一下为什么我的代码不起作用,如果可以的话,为什么你的代码会起作用,这样我就可以学习了。 谢谢! -JJ
代码:
@client.command()
async def verify(ctx):
verifier = ctx.author
jj = await client.fetch_user(270397954773352469)
validReactions = ['✅', '????']
role = discord.utils.get(ctx.guild.roles, name="Verified")
await ctx.send(f'verifier... Awaiting Verification, you will recieve a dm when you are verified')
dm = await jj.send(f'verifier.mention is trying to be verified, do you know him/her?')
await dm.add_reaction("✅")
await dm.add_reaction("????")
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in validReactions
reaction, user = await client.wait_for('reaction_add', timeout=float('inf') , check=check) #float('inf') for no timeout on when I can add the reaction for yes or no
if str(reaction.emoji) == "✅":
await verifier.send("You have been verified")
await client.add_roles(verifier, role)
elif str(reaction.emoji) == "????":
await verifier.send("You have not been verified, please try again if you think this was a mistake, or contact the owner")
【问题讨论】:
【参考方案1】:您在check
函数中向名为jj
和user == ctx.author
的人发送消息始终为True。 (因为ctx.author
看不到该消息)。所以,尝试替换
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in validReactions
与
def check(reaction, user):
return user == jj and str(reaction.emoji) in validReactions
【讨论】:
以上是关于.verify 命令未赋予角色(discord.py 1.7.3)的主要内容,如果未能解决你的问题,请参考以下文章