【问题标题】:Can someone please tell me whats wrong with this code有人可以告诉我这段代码有什么问题吗
【发布时间】:2020-10-30 19:38:33
【问题描述】:
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)

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

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    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-02-21
    • 2010-11-08
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多