Check if User has a certain role

后端 未结 2 617
灰色年华
灰色年华 2021-01-25 13:14

I have code in which you can type -giverole e.g. -giverole @Soup Board of Executives.
What I need now is a method tha

2条回答
  •  失恋的感觉
    2021-01-25 14:17

    You can use discord.Member.roles to do something like

    from discord.utils import get
    
    @client.command(pass_context=True)
    async def giverole(ctx, member: discord.Member, *, role: discord.Role):
      check_role = get(ctx.message.server.roles, name='Board of Executives')
      if check_role not in member.roles:
        await client.say(f"You don't have the role '{str(role)}'")
      else:
        await client.add_roles(member, role)
        await client.say(f"The role '{str(role)}' has been given to {member.mention}.")
    

提交回复
热议问题