I am trying to make a discord bot in Nextcord Python that will generate a random recipe using a $randomrecipe command. I tried making it so that it would send a title of a dish (and also the image and ingredients) but I cant get it to work.
@bot.command(name='randomrecipe')
async def randomrecipe(ctx):
r = requests.get('https://api.spoonacular.com/recipes/random?apiKey=apikey')
title_name = r.json() ["title"]
await ctx.send(title_name)
here's the error for that code
Ignoring exception in command randomrecipe:
Traceback (most recent call last):
File "C:\Users\iliaa\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 168, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\iliaa\Downloads\json\app.py", line 22, in randomrecipe
title_name = r.json() ["title"]
KeyError: 'title'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\iliaa\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\bot.py", line 1048, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\iliaa\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 933, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\iliaa\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 177, in wrapped
raise CommandInvokeError(exc) from exc
nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'title'