Jhon87
Jhon87

Reputation: 49

Discord.py: How to get the colors of the roles?

I'm trying to make my first bot for discord. What I'm trying to achieve is to get the color of all the roles in a server. How can I do that? I searched but I found only how to set a color of a role and not how to get the current color. Thank you in advance for any help.

@client.command()
async def roles_colors(ctx):
    for role in ctx.guild.roles:
        await ctx.send(role.name)
        await ctx.send(discord.role.color)

Upvotes: 1

Views: 6138

Answers (1)

Tin Nguyen
Tin Nguyen

Reputation: 5330

You can get the colour of a discord.Role object with .colour. https://discordpy.readthedocs.io/en/latest/api.html?highlight=roles#discord.Role.colour

You can get all the Roles of a discord.Guild object with .roles. (A discord guild is a discord server.) https://discordpy.readthedocs.io/en/latest/api.html?highlight=roles#discord.Guild.roles

If your question is how to get the rendered colour of a Discord Member (member with multiple coloured roles) you just access .colour on the discord.Member object.
https://discordpy.readthedocs.io/en/latest/api.html?highlight=roles#discord.Member.colour

edit:

@client.command()
async def roles_colors(ctx):
    for role in ctx.guild.roles:
        await ctx.send(role.name)
        await ctx.send(role.color)

You wrote discord.role.color, should be role.color.

Upvotes: 2

Related Questions