【问题标题】:Discord.py Reaction RolesDiscord.py 反应角色
【发布时间】:2021-03-12 11:25:21
【问题描述】:

我正在创建一个反应角色频道,如果您使用表情符号做出反应,它会为您提供相应的角色。我在我的验证系统中使用了完全相同的代码,它运行良好。但是由于某种原因,当我使用相应的表情符号对消息做出反应时,我没有得到角色,没有显示回溯,并且我没有在控制台中看到“给某人一个角色”的消息。

代码:

async def roles(ctx):
  embed=discord.Embed(title="Reaction Roles", description="React with the corresponding emoji to get the role", color=0xff0000, timestamp=datetime.now())
  embed.set_author(name="Official Gnag Discord", icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
  embed.add_field(name="⛓️", value="Role 1", inline=True)
  embed.add_field(name="????", value="Role 2", inline=True)
  embed.add_field(name="????", value="Role 3", inline=True)
  embed.add_field(name="????️‍????", value="Role 4", inline=True)
  embed.add_field(name="????", value="Role 5", inline=True)
  embed.add_field(name="????", value="Role 6", inline=True)
  embed.add_field(name="????", value="Role 7", inline=True)
  embed.add_field(name="✔️", value="Role 8", inline=True)
  embed.add_field(name="????", value="Role 9", inline=True)
  embed.add_field(name="????", value="Role 10", inline=True)
  embed.add_field(name="♂️", value="Role 11", inline=True)
  embed.set_footer(text="Official Gnag Discord Bot Made By @Lukeee#6032")
  msg = await ctx.send(embed=embed)
  await msg.add_reaction('????')
  await msg.add_reaction('✔️')
  await msg.add_reaction('????')
  await msg.add_reaction('????')
  await msg.add_reaction('♂️')
  await msg.add_reaction('⛓️')
  await msg.add_reaction('????')
  await msg.add_reaction('????')
  await msg.add_reaction('????️‍????')
  await msg.add_reaction('????')
  await msg.add_reaction('????')


@bot.event
async def on_raw_reaction_add(payload):
    ourMessageID = 819597141743763467

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

      emoji = payload.emoji.name
      if emoji == '????':
        mrole = discord.utils.get(guild.roles, name='Role 7')
        await member.add_roles(mrole)
        print ('gave a role to someone')

【问题讨论】:

  • 那有什么问题?
  • 欢迎来到 StackOverflow。请阅读how-to-ask 并提出正确的问题
  • 每当我添加一个反应,没有错误弹出或任何东西时,我还在控制台中将它编码为“给某人一个角色”,它没有这么说。

标签: python python-3.x discord.py


【解决方案1】:

嘿,虽然你没有说你发出的问题是我想该命令不能正常工作。我建议你这样做:

async def roles(ctx):
      embed=discord.Embed(title="Reaction Roles", description="React with the corresponding emoji to get the role", color=0xff0000)
      embed.set_author(name="Official Gnag Discord", icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
      embed.add_field(name="⛓️", value="Role 1", inline=True)
      embed.add_field(name="?", value="Role 2", inline=True)
      embed.add_field(name="?", value="Role 3", inline=True)
      embed.add_field(name="?️‍?", value="Role 4", inline=True)
      embed.add_field(name="?", value="Role 5", inline=True)
      embed.add_field(name="?", value="Role 6", inline=True)
      embed.add_field(name="?", value="Role 7", inline=True)
      embed.add_field(name="✔️", value="Role 8", inline=True)
      embed.add_field(name="?", value="Role 9", inline=True)
      embed.add_field(name="?", value="Role 10", inline=True)
      embed.add_field(name="♂️", value="Role 11", inline=True)
      embed.set_footer(text="Official Gnag Discord Bot Made By @Lukeee#6032")
      msg = await ctx.send(embed=embed)
      await msg.add_reaction('?')
      await msg.add_reaction('✔️')
      await msg.add_reaction('?')
      await msg.add_reaction('?')
      await msg.add_reaction('♂️')
      await msg.add_reaction('⛓️')
      await msg.add_reaction('?')
      await msg.add_reaction('?')
      await msg.add_reaction('?️‍?')
      await msg.add_reaction('?')
      await msg.add_reaction('?')

      def check(reaction, user):

            return user == ctx.user and reaction.message == msg and str(reaction.emoji) in ['?','✔','?','?','♂','⛓','?','?','?️‍?','?','?']

      while True:
           try:
               reaction, user = await client.wait_for("reaction_add", check=check)

               if str(reaction.emoji) == '?':
                    mrole = discord.utils.get(ctx.guild.roles, name='Role 7')
                    await user.add_roles(mrole)
                    print ('gave a role to someone')
               

Ps 在复制和粘贴之前,请阅读它。它甚至可能不适合你。

编辑:您也可以加入 discord.py 服务器以获得更多帮助discord.py

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-16
    • 2021-04-02
    • 2021-10-10
    • 2021-04-18
    • 2020-10-03
    • 1970-01-01
    • 2019-04-20
    • 1970-01-01
    相关资源
    最近更新 更多