How to sort out default role from member.roles?

Question:

I’m trying to make a userinfo command which displays the user’s roles. I’ve separated the roles with a space. But I don’t know how to remove the default role out of the roles list.

At the moment, the message looks like this:

@@everyone @role @role @role

But I don’t want that @@everyone in there.

My code right now:

@client.command(aliases=['whois', 'user'])
async def userinfo(ctx, member: discord.Member):

    embed = discord.Embed(color=member.top_role.color.value, title=f'About {member}')
    embed.add_field(name=f'**Roles [{len(member.roles)}]**', value=' '.join([role.mention for role in member.roles]), inline=True)

    await ctx.send(embed=embed)
Asked By: puncher

||

Answers:

Try to use: [role.mention for role in roles[1:]] instead of: [role.mention for role in member.roles] or delete first element. Because you’ll get @everyone every time.

Documentation for Member.roles:

A list of Role that the member belongs to. Note that the first element of this list is always the default ‘@everyone’ role.

Before:

Before

After:

enter image description here

Answered By: user12991524
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.