Finlay Metcalfe
Finlay Metcalfe

Reputation: 143

Cannot get role to change colours

I've got a piece of code that takes a specified role and that roles server and puts it into a list, and any roles that are in the list should change colour but well.... it doesn't.

code:

@client.command(pass_context=True,description="Linusifies a role")
@has_permissions(administrator = True)
async def rgb(ctx, role : discord.Role):
    server = ctx.message.author.server
    if (("{}, {}").format(server, role)) in rgb_list:
        msg = "{}'s rgb is turned off :disappointed_relieved:".format(role)
        rgb_list.remove(("{}, {}").format(server, role))
        await client.send_message(ctx.message.channel, msg)
        print (server)

    else:
        msg = "{}'s rgb has been turned on :christmas_tree:".format(role)
        rgb_list.append(("{}, {}").format(server, role))
        await client.send_message(ctx.message.channel, msg)
        print (server)

and in my @client.event:

   async def rgb_():
    await client.wait_until_ready()
    while not client.is_closed:
        print (rgb_list)
        await client.edit_role(rgb_list,colour=discord.Colour(0x1abc9c))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0x11806a))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0x2ecc71))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0x1f8b4c))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0x3498db))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0x206694))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0x9b59b6))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0x71368a))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0xe91e63))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0xad1457))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0xf1c40f))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0xc27c0e))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0xe67e22))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0xa84300))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0xe74c3c))
        await asyncio.sleep(2)
        await client.edit_role(rgb_list,colour=discord.Colour(0x992d22))
        await asyncio.sleep(2)

Upvotes: 1

Views: 1377

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 61014

Read the documentation for Client.edit_role. edit_role takes a Server and a Role, not a list of strings. You should be storing your list of roles as a list of Roles. Then you can loop over that lsit to change the colours.

@client.command(pass_context=True,description="Linusifies a role")
@has_permissions(administrator = True)
async def rgb(ctx, role : discord.Role):
    server = ctx.message.author.server
    if role in rgb_list:
        msg = "{}'s rgb is turned off :disappointed_relieved:".format(role.name)
        rgb_list.remove(role)
        await client.send_message(ctx.message.channel, msg)
        print (server)

    else:
        msg = "{}'s rgb has been turned on :christmas_tree:".format(role.name)
        rgb_list.append(role)
        await client.send_message(ctx.message.channel, msg)
        print (server)

colours = [discord.Colour(0x1abc9c), discord.Colour(0x11806a)]

@client.event
async def on_ready():
    while not client.is_closed:
        for colour in colours:  # make a list of Colours
            for role in rgb_list:
                await client.edit_role(role.server, role, colour=colour)
            await asyncio.sleep(2)

Upvotes: 1

Related Questions