【发布时间】:2021-06-24 07:12:21
【问题描述】:
我有一个不和谐的机器人,它允许为配置添加默认颜色。
{
"Embed-Default-Color": "0x000000"
}
它不允许没有“”的原始输入并导致使用问题:
with open("config.json") as f:
config = json.load(f)
DEFAULT_COLOR = config.get("Embed-Default-Color")
em = discord.Embed(title="Hi", description="I'm Gabe Newell", color=DEFAULT_COLOR)
(代码仅用于上下文展示,没有找不到配置等错误)
错误返回TypeError: Cannot use string for argument discord.Colour => "0x000000"
如何将字符串转换为十六进制,而不让它转换任何内容,因为它已经是十六进制,但格式错误?
【问题讨论】:
-
您是在问如何将包含十六进制的字符串转换为整数?为什么 int("0x000000",16) 不起作用?
-
是的,成功了,非常感谢
标签: python string discord hex discord.py