Reputation: 118
I tryed to make the embed color based on the config.json
value
with open('config.json') as f:
config = json.load(f)
a_color = config.get("hexcolor") #Config Text {"hexcolor": "#FFFFF"}
s_color = a_color.replace("#", "0x")
@bot.command()
async def example(ctx):
await ctx.message.delete()
embed = discord.Embed(title="Title", description="Some description Text", color=discord.Colour(s_color))
await ctx.send(embed=embed)
But my output is:
embed = discord.Embed(title="Title", description="Some description Text", colour=discord.Colo
ur(s_color))
File "C:\Users\public\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\colour.py
", line 63, in __init__
raise TypeError('Expected int parameter, received %s instead.' % value.__class__.__name__)
TypeError: Expected int parameter, received str instead.
Why?
Upvotes: 2
Views: 534
Reputation: 15689
It's easier if put the hex color already like this in the json file:
{"hexcolor": "0xFFFFFF"}
To convert the string to a hex int:
>>> int('0xFFFFFF', 16)
16777215
And you simply need to pass that to the colour
kwarg
Your code should look like this:
colour = int(config.get('hexcolor'), 16) # {"hexcolor": "0xFFFFFF"}
@bot.command()
async def example(ctx):
embed = discord.Embed(title='whatever', colour=colour)
await ctx.send(embed=embed)
Upvotes: 3