我正在制作一个不和谐机器人,当我尝试运行命令时,我得到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"])
答案 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