简体   繁体   English

Discord.py 嵌入颜色变化

[英]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)

I made a discord.py color class from which i got these colors from btw.我做了一个 discord.py 颜色类,我从 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希望这会有所帮助,如果不只是问不好尽我所能提供帮助

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM