【发布时间】: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")
【问题讨论】:
标签: python-3.x discord.py