我尝试根据config.json
值生成嵌入颜色
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)
但我的输出是:
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.
为什么?
如果将十六进制颜色像这样放在json文件中会更容易:
要将字符串转换为十六进制整数:
您只需将其传递给
colour
kwarg您的代码应该如下所示:
相关问题 更多 >
编程相关推荐