此代码:
@commands.command(name="currency", aliases=['ce'])
async def currencyexchange(self, ctx, currency1, currency2, amount:str):
url = "https://www.amdoren.com/api/currency.php?api_key=WTkbre7JxKME95tsu62R2bBng42rKE&from=" + currency1 + "&to=" + currency2 + "&amount=" + amount
async with ClientSession() as session:
async with session.get(url) as response:
r = await response.json(content_type=None)
embed = discord.Embed(colour=discord.Colour.purple(), timestamp = ctx.message.created_at, title=f"Currency Rates")
embed.set_footer(text=f"Requested by {ctx.author}")
embed.add_field(name=f"Exchanged", value = f"{r('amount')}", inline = False)
await ctx.send(embed=embed)
返回标题中显示的错误。不知道我在哪里搞砸了,但我需要一些帮助
API返回以下内容:
{
"error" : 0,
"error_message" : "-",
"amount" : 6.31656
}
谢谢
在这一行:
当你写
r('amount')
时,用括号把r
当作一个函数。为了从r
中获取amount
字段的值,需要使用方括号。它看起来是这样的:相关问题 更多 >
编程相关推荐