【发布时间】:2021-12-26 01:08:09
【问题描述】:
我正在尝试让这段代码工作,它将一些 JSON 输出传递到 discord.py 嵌入中,但我遇到了一些问题,这是我的一段代码。
@client.event
async def on_message(message):
if message.content.startswith('!hello'):
print("dick")
embed = discord.Embed(title="Verium Mining", url="https://wiki.vericoin.info/images/thumb/b/b5/Verium-01.png/176px-Verium-01.png", color=0x5da3fd)
embed.add_field(name="Balance", value='%s coins', inline=False) % (json.loads(requests.get('https://vrm.mining-pool.ovh/index.php?page=api&action=getuserbalance&api_key=90ccec2fe5216ee73f6143ab3f59804d914a0df65165bedddd6f7a78fb6ffd15&id=4483').text)['getuserbalance']['data']['confirmed'])
embed.add_field(name="Hashrate", value="undefined", inline=False)
embed.add_field(name="Sharerate", value="undefined", inline=False)
embed.set_footer(text="undefined")
运行时出现以下错误:
TypeError: unsupported operand type(s) for %: 'Embed' and 'str'
我该如何解决这个问题?
提前致谢
【问题讨论】:
-
您的意思是将
%运算符应用于字符串文字'%s coins'? -
是的,所以输出是“硬币数量”硬币
-
那么你的意思是
value='%s coins'%json.loads(...)。您将%运算符应用于错误的对象。如果您不尝试在一行中做这么多,您的代码会更清晰。 -
是的,但我将如何在代码中实现它?
标签: python json discord.py typeerror operands