有没有办法将十六进制代码从字符串转换为 discord.py 支持的十六进制颜色?
Is there any way to convert the hex code from string to hex colour which discord.py supports?
我想弄清楚这个问题已经很久了,
但我无法像这样将十六进制代码从字符串转换为实际的十六进制代码 0xFFFFFF
因为 discord.py 不采用 str 数据类型中的十六进制代码。
代码片段:-
@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))
错误:-
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.
这就是我在 mongodb atlas 数据库中存储十六进制代码的方式->
编辑:-
它致力于使用 inte
而不是 color
>>> 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
看看错误。
TypeError: Expected discord.Colour, int, or Embed.Empty
一个int
就足够了,不需要额外的转换。
@client.command()
async def testing(ctx):
# color = lgd.hexConvertor(colorCollection.find({},{"_id":0,"Hex":1}))
c = "0xFFFFFF"
int_colour = int(c,16)
await ctx.send(embed = discord.Embed(description = "testing",color = int_colour))
这是一个包含discord.py支持
代码的多种颜色列表
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
我想弄清楚这个问题已经很久了,
但我无法像这样将十六进制代码从字符串转换为实际的十六进制代码 0xFFFFFF
因为 discord.py 不采用 str 数据类型中的十六进制代码。
代码片段:-
@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))
错误:-
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.
这就是我在 mongodb atlas 数据库中存储十六进制代码的方式->
编辑:-
它致力于使用 inte
而不是 color
>>> 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
看看错误。
TypeError: Expected discord.Colour, int, or Embed.Empty
一个int
就足够了,不需要额外的转换。
@client.command()
async def testing(ctx):
# color = lgd.hexConvertor(colorCollection.find({},{"_id":0,"Hex":1}))
c = "0xFFFFFF"
int_colour = int(c,16)
await ctx.send(embed = discord.Embed(description = "testing",color = int_colour))
这是一个包含discord.py支持
代码的多种颜色列表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