【发布时间】:2022-01-16 07:01:06
【问题描述】:
我尝试创建一个 discord.py 机器人命令来发送随机的狗事实和图像,但我遇到了这个错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'link'
代码如下:
@bot.command()
async def dog(ctx):
response = requests.get('https://some-random-api.ml/animal/dog')
json_data = json.loads(response.text)
embed = discord.Embed(color = 0xff9900, title = 'random dog fact')
embed.set_image(url = json_data['link'])
await ctx.send(embed = embed)
【问题讨论】:
标签: python python-3.x discord.py