Flexes
Flexes

Reputation: 107

Can someone please tell me whats wrong with this code

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)

I am getting this error when I run this code:

reference

Upvotes: 1

Views: 80

Answers (1)

joshua.software.dev
joshua.software.dev

Reputation: 307

Inside f'' strings, if you need to access something using another string, its best to use the other quote type.

In this case:

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

is invalid syntax since you have sets of quotes within a string literal. The correct way to do it in this case is:

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

Note the use of double quotes. Alternative options include:

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

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

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

All of these options are valid and have their uses.

Upvotes: 5

Related Questions