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)
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:
After:
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)
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:
After: