Discord.py嵌入颜色更改

时间:2020-09-06 14:47:29

标签: python discord.py

我一直在研究Web抓取的Discord机器人。如何根据变量更改嵌入的颜色?我以前尝试过下面的代码,但没有改变颜色。

  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)

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我做了一个discord.py颜色类,从btw那里得到了这些颜色。

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

这是颜色类别:

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

希望这不仅对生病有帮助,还是会有所帮助