Делаю дискорд бота на python и делаю "цветные команды", но на этот код:
@bot.command()
async def hsv(ctx, h,s,v):
try:
h = float(h)
s = float(s)
v = float(v)
r,g,b = colorsys.hsv_to_rgb(h, s, v)
RGB_SCALE = 255
CMYK_SCALE = 100
def rgb_to_cmyk(r, g, b):
if (r, g, b) == (0, 0, 0):
# black
return 0, 0, 0, CMYK_SCALE
# rgb [0,255] -> cmy [0,1]
c = 1 - r / RGB_SCALE
m = 1 - g / RGB_SCALE
y = 1 - b / RGB_SCALE
# extract out k [0, 1]
min_cmy = min(c, m, y)
c = (c - min_cmy) / (1 - min_cmy)
m = (m - min_cmy) / (1 - min_cmy)
y = (y - min_cmy) / (1 - min_cmy)
k = min_cmy
# rescale to the range [0,CMYK_SCALE]
return c * CMYK_SCALE, m * CMYK_SCALE, y * CMYK_SCALE, k * CMYK_SCALE
c,m,y,k = rgb_to_cmyk(r, g, b)
hL,sL,L = colorsys.rgb_to_hls(r, g, b)
def rgb_to_hex(rgb):
return '%02x%02x%02x' % rgb
hex_code = rgb_to_hex((r,g,b))
embed = discord.Embed(title = f"{h},{s},{v} - я понял что это за цвет!",color = discord.Colour.from_rgb(r, g, b))
embed.add_field(name = "CMYK", value = f"{c},{m},{y},{k}", inline = False)
embed.add_field(name = "RGB", value = f"{r},{g},{b}", inline = False)
embed.add_field(name = "hls", value = f"{hL},{L},{sL}", inline = False)
embed.add_field(name = "Hex-code", value = hex_code, inline = False)
await ctx.reply(embed = embed)
return
except Exception as e:
await ctx.reply(e)
@bot.command()
async def hls(ctx, h, l, s):
try:
h = float(h)
l = float(l)
s = float(s)
r,g,b = colorsys.hls_to_rgb(h, l, s)
RGB_SCALE = 255
CMYK_SCALE = 100
def rgb_to_cmyk(r, g, b):
if (r, g, b) == (0, 0, 0):
# black
return 0, 0, 0, CMYK_SCALE
# rgb [0,255] -> cmy [0,1]
c = 1 - r / RGB_SCALE
m = 1 - g / RGB_SCALE
y = 1 - b / RGB_SCALE
# extract out k [0, 1]
min_cmy = min(c, m, y)
c = (c - min_cmy) / (1 - min_cmy)
m = (m - min_cmy) / (1 - min_cmy)
y = (y - min_cmy) / (1 - min_cmy)
k = min_cmy
# rescale to the range [0,CMYK_SCALE]
return c * CMYK_SCALE, m * CMYK_SCALE, y * CMYK_SCALE, k * CMYK_SCALE
c,m,y,k = rgb_to_cmyk(r, g, b)
hV,sV,V = colorsys.rgb_to_hsv(r, g, b)
def rgb_to_hex(rgb):
return '%02x%02x%02x' % rgb
hex_code = rgb_to_hex((r,g,b))
embed = discord.Embed(title = f"{h},{l},{s} - я понял что это за цвет!",color = discord.Colour.from_rgb(r, g, b))
embed.add_field(name = "CMYK", value = f"{c},{m},{y},{k}", inline = False)
embed.add_field(name = "RGB", value = f"{r},{g},{b}", inline = False)
embed.add_field(name = "hsv", value = f"{hV},{sV},{V}", inline = False)
embed.add_field(name = "Hex-code", value = hex_code, inline = False)
await ctx.reply(embed = embed)
return
except Exception as e:
await ctx.reply(e)
выводит следующую ошибку:
%x format: an integer is required, not float
colorsys стоит, ибо остальные команды с ним работают
Помогите, пожалуйста!