Discord.py: How to change role color?

2.6k views Asked by At

So i created this role for my discord bot and i want to change his color to yellow. I don't know why it won't change the color. This is my code, can anyone help me with it?

@bot.command(pass_context=True)
async def add_role(ctx):
    member = ctx.author
    role = discord.utils.get(member.guild.roles, name="Spike")
    await member.add_roles(role)
    await role.edit(colour=discord.colour(0xFFFF00))
    print("done")

edit: It doesn't print the "done"

3

There are 3 answers

0
AudioBubble On BEST ANSWER

Ok so, my problem was that my bot.command wasn't working because I was using bot and client method at the same time. I wasn't aware that they can't work togheter, so I decided to only use bot, and now everything is working.

1
actuallyatiger On

On the following line await role.edit(colour=discord.colour(0xFFFF00)), it looks like you missed the capitalisation of Colour in the discord class. This should be correct, unless the API already handles this.

await role.edit(colour=discord.Colour(0xFFFF00))

3
Ali Hakan Kurt On

Can you try this:

@bot.command(pass_context=True)
async def add_role(ctx):
    member = ctx.author
    role = discord.utils.get(member.guild.roles, name="Spike")
    await member.add_roles(role)
    await role.edit(colour=0xFFFF00)
    print("done")