'Is there any way to convert the hex code from string to hex colour which discord.py supports?
I am trying to figure this out for so long,
but I am not able to convert the hex code from string to actual hex code like this 0xFFFFFF
since discord.py doesn't take hex code in str datatype.
Code Snippet:-
@client.command()
async def testing(ctx):
# color = lgd.hexConvertor(colorCollection.find({},{"_id":0,"Hex":1}))
c = "0xFFFFFF"
inte = int(c,16)
color = hex(inte)
await ctx.send(embed = discord.Embed(description = "testing",color = color))
Error:-
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 221, in testing
await ctx.send(embed = discord.Embed(description = "testing",color = color))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/embeds.py", line 115, in __init__
self.colour = colour
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/embeds.py", line 230, in colour
raise TypeError('Expected discord.Colour, int, or Embed.Empty but received %s instead.' % value.__class__.__name__)
TypeError: Expected discord.Colour, int, or Embed.Empty but received str instead.
This is how I stored the hex codes in my mongodb atlas database->

Edit:-
It worked on using inte instead of color
Solution 1:[1]
>>> color = "0xFFFFFF"
>>> int_color = int(color,16)
>>> hex(int_color)
'0xffffff'
>>> # basically the same thing
>>>
>>> from discord import Color
>>>
>>> Color(int_color)
<Colour value=16777215>
>>> #just ints work
Solution 2:[2]
This is a list of a lot of colors with the codes that discord.py supports
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | pkapetsonis |
