【问题标题】:Discord.py Verification SystemDiscord.py 验证系统
【发布时间】:2021-06-12 08:55:18
【问题描述】:

我正在制作一个验证系统,如果您输入!verify "1. John 2. Mr. Teacher 3. Somewhere 4. Freshman 5. The Cool Mascot",它将在频道中发送一个嵌入,如下所示:https://gyazo.com/ab808bafcd4a5f3ed05f63e007da20c1。 如果有人对复选标记做出反应,我想告诉用户他们已被接受,如果他们被拒绝,它将发送一条 dm 说他们已被拒绝,但我在做出反应时似乎没有收到 dm,他们也没有得到会员角色紧随其后,并且没有任何追溯。

代码:

@bot.command(pass_context=True)
async def verify(ctx, message):
  logem = discord.Embed(color=discord.Color.red())
  logem.set_author(name=f"Verification Request!")
  logem.add_field(name="User", value=f"{ctx.author.mention}")
  logem.add_field(name="Application", value=f"{message}")
  logem.set_footer(text=f"React with ✅ to accept the application and ❌ to deny the application",
                           icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
  logemlog = bot.get_channel(820840787645956123)
  msg = await logemlog.send(embed=logem)
  await msg.add_reaction('✅')
  await msg.add_reaction('❌')

async def on_raw_reaction_add(payload):
    msgid = await ctx.fetch_message(msgID)
    ourMessageID = msgid

    if ourMessageID == payload.message_id:
      member = payload.member
      guild = member.guild

      emoji = payload.emoji.name
    if emoji == '✅':
      role = discord.utils.get(guild.roles, name="Member")
      print ('Accepted Someones Application')
      em = discord.Embed(color=discord.Color.red())
      em.set_author(name="Verified!")
      em.set_footer(text=f"You Have Been Accepted Into The Official WHS Discord Server!",
                           icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
      await member.send("You have been accepted!")
      await member.add_roles(role)
    elif emoji == '❌':
      em = discord.Embed(color=discord.Color.red())
      em.add_field(name="Denied!", value=f"{message}")
      em.set_footer(text=f"You Have Been Denied Access Into The Official WHS Discord Server!",
                           icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
      await ctx.member.send("You have been Denied!")

【问题讨论】:

  • 您有什么理由使用on_raw_reaction_add 而不是wait_for?你也没有添加 bot.event 装饰器
  • 哦,我什至没有意识到我没有 bot.event 装饰器,我也尝试使用等待,但它也会吐出一个错误
  • 那么没有装饰器的事件应该如何工作? wait_for 也是一个更好的解决方案
  • 好的,我试试,我会告诉你的。

标签: discord.py


【解决方案1】:

使用它来代替 async def on_raw_reaction_add:

def check(reaction, user):
        return reaction.emoji in ['✅', '❌'] and user == ctx.author
while True:
        try:
            reaction, user = await bot.wait_for('reaction_add', check=check)

        except Exception as e:

            print(e)
        else:
            if reaction.emoji == '✅':
                role = discord.utils.get(guild.roles, name="Member")
                print ('Accepted Someones Application')
                em = discord.Embed(color=discord.Color.red())
                em.set_author(name="Verified!")
                em.set_footer(text=f"You Have Been Accepted Into The Official WHS Discord Server!",
                    icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
                await member.send("You have been accepted!")
                await member.add_roles(role)
           if reaction.emoji == '❌':
               em = discord.Embed(color=discord.Color.red())
               em.add_field(name="Denied!", value=f"{message}")
               em.set_footer(text=f"You Have Been Denied Access Into The Official WHS Discord Server!",
                           icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
               await ctx.member.send("You have been Denied!")

测试一下,如果它不起作用,请告诉我。

【讨论】:

  • 不,很高兴为您提供帮助!
猜你喜欢
  • 1970-01-01
  • 2020-08-06
  • 2021-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-07
  • 1970-01-01
相关资源
最近更新 更多