Reputation: 21
I want my bot to show me the list of the users roles. If I use user.roles
, I get this problem:
Is there a way to let the bot list the roles clean, just like this bot does?
Upvotes: 1
Views: 3174
Reputation: 6944
You're having a list of roles returned. This allows you to iterate over it, picking each individual attribute of a role.
For example, the attribute in the second image you've chosen was .mention
, and the general idea of the code looks like this (adapt it for your own command):
@bot.command()
async def roles(...):
rolelist = [r.mention for r in user.roles if r != ctx.guild.default_role]
roles = ", ".join(rolelist)
The list comprehension is getting every role that the user has, excluding @everyone
.
roles
is the variable that contains the "beautified" list of roles. And to get the number of roles, just do len(rolelist)
.
References:
Upvotes: 4