IAmAHuman
IAmAHuman

Reputation: 309

(discord.py) How can I get a list of how many permissions a user has

I am currently making a "userinfo" command for my bot which returns general stuff like the user's ID, roles, profile picture, etc. And I also wanted it to display a list of how many permissions the mentioned user has. Here's the part of the code where I defined member just for context:

@client.command(aliases=["whois"])
async def userinfo(ctx, member: discord.Member = None):
    if not member:  # if member is no mentioned
        member = ctx.message.author  # set member as the author
    ...

I am aware that you can do member.guild_permissions.<permission> which returns whether the user has a permission or not but I wanted to know if there was a way to just get a list of how many permissions a user has without having to check for every permission.

So is there a way to do that?

Upvotes: 0

Views: 2108

Answers (1)

MrSpaar
MrSpaar

Reputation: 3994

You can actually use Member.guild_permissions:

@client.command(aliases=["whois"])
async def userinfo(ctx, member: discord.Member = None):
    if not member:
        member = ctx.message.author
    perm_list = [perm[0] for perm in member.guild_permissions if perm[1]]

Member.guild_permission returns a list of tuples (eg. (manage_permissions, True)). You can explore this list and add the permission to another list if it is True.

Upvotes: 2

Related Questions