KeyError:('url','text')

时间:2018-06-06 21:23:40

标签: python-3.x discord.py

我正在制作一个不和谐机器人,当我尝试运行命令时,我得到KeyError :('url','text')

@bot.command(pass_context=True)
    async def test(ctx):
        async with aiohttp.ClientSession() as cs:
        async with cs.get('https://api-to.get-a.life/meme') as r:
            res = await r.json()
            await bot.say(res["url", "text"])

1 个答案:

答案 0 :(得分:0)

您正在使用两个键从字典中获取值,这是错误的语法使用

res["url"]res["text"]

喜欢

@bot.command(pass_context=True)
    async def test(ctx):
        async with aiohttp.ClientSession() as cs:
        async with cs.get('https://api-to.get-a.life/meme') as r:
            res = await r.json()
            url = res["url"]
            text = res["text"]
            await bot.say(url, text) # or whatever parameter your bot accepts