1
response = get(url='https://benbotfn.tk/api/v1/aes')
 
data = response.json()
 
 
@client.command()
async def aes123(ctx):
  await ctx.send(data['mainKey'])
 
 
@client.command()
async def aeskey(ctx):
 embed=discord.Embed(title="aes")
 embed.add_field(name='aes', value=f'{data['mainKey']} aes key')
 


 await ctx.send(embed=embed)

运行此代码时出现此错误:

参考

4

1 回答 1

5

f''字符串内部,如果您需要使用另一个字符串访问某些内容,最好使用其他引号类型。

在这种情况下:

value=f'{data['mainKey']} aes key'

是无效的语法,因为您在字符串文字中有多组引号。在这种情况下,正确的做法是:

value=f'{data["mainKey"]} aes key'

注意使用双引号。替代选项包括:

value=f"{data['mainKey']} aes key"

value=f'''{data['mainKey']} aes key'''

value=f"""{data["mainKey"]} aes key"""

所有这些选项都是有效的并且有它们的用途。

于 2020-07-10T05:42:52.903 回答