Discord.py commands for cat image with breed information

RMAG news
@commands.hybrid_command(name=”cat”, description = “Get a random cat image with description”)
@commands.cooldown(4, 20, commands.BucketType.guild)
async def cat(self, ctx: commands.Context, user: discord.Member = None):
api_key = os.getenv(“CAT_API_KEY”)
url = “https://api.thecatapi.com/v1/images/search?has_breeds=1”
reponse = requests.get(url, headers={‘x-api-key’: f”{api_key}”})

data = reponse.json()

breed = [breed[‘breeds’] for breed in data]
image = [image[‘url’] for image in data]
cat = breed[0][0]
cat_name = cat[‘name’]
cat_description = cat[‘description’]
cat_temperament = cat[‘temperament’]

embed=discord.Embed(title=f”{cat_name}”, description=f”>>> {cat_description}”, color=0x00FFFF)
embed.add_field(name=”Temperament”, value=f”>>> {cat_temperament}”, inline=False)
embed.set_image(url=f”{image[0]}”)

if user:
await ctx.send(user.mention,embed=embed)
else:
await ctx.send(embed=embed)

Please follow and like us:
Pin Share