【问题标题】:.verify command not giving role (discord.py 1.7.3).verify 命令未赋予角色(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")

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    您在check 函数中向名为jjuser == 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 2021-04-12
      • 1970-01-01
      • 2019-02-12
      • 2021-04-09
      • 2021-07-06
      • 2021-02-07
      相关资源
      最近更新 更多