Lucas
Lucas

Reputation: 41

Discord.py embed colour changing

I have been working on a discord bot that web scrapes. How I could change the colour of an embed depending on the variable? I tried the code below previously but it did not change the colour.

  embed2 = discord.Embed(title=username,description=online, color=0xf21f18)
        embed2.add_field(name="profile", value= links, inline=False)
        embed = discord.Embed(title=username,description=online, color=0x1adb64)
        embed.add_field(name="profile", value= links, inline=False)
        if online == "offline" or "Offline":
            await ctx.send(embed=embed2)
         
        else:
            await ctx.send(embed=embed)

Upvotes: 1

Views: 3700

Answers (2)

Remi_Zacharias
Remi_Zacharias

Reputation: 328

I made a discord.py color class from which i got these colors from btw.

if online:
    color = colors.red
else:
    color = colors.green
    
embed = discord.Embed(title="Title", description='Desc', color=color)

Here's the color class:

class colors:
    default = 0
    teal = 0x1abc9c
    dark_teal = 0x11806a
    green = 0x2ecc71
    dark_green = 0x1f8b4c
    blue = 0x3498db
    dark_blue = 0x206694
    purple = 0x9b59b6
    dark_purple = 0x71368a
    magenta = 0xe91e63
    dark_magenta = 0xad1457
    gold = 0xf1c40f
    dark_gold = 0xc27c0e
    orange = 0xe67e22
    dark_orange = 0xa84300
    red = 0xe74c3c
    dark_red = 0x992d22
    lighter_grey = 0x95a5a6
    dark_grey = 0x607d8b
    light_grey = 0x979c9f
    darker_grey = 0x546e7a
    blurple = 0x7289da
    greyple = 0x99aab5

Hope this helps if not just ask ill try my best to help

Upvotes: 2

Ozballer31
Ozballer31

Reputation: 453

embed = discord.Embed(color=0xf21f18 if online.lower() == 'offline' else 0x1adb64)
await ctx.send(embed=embed)

Upvotes: 0

Related Questions