29 lines
932 B
Python
29 lines
932 B
Python
import discord
|
||
from discord.ext import commands
|
||
import requests
|
||
|
||
|
||
class Cat(commands.Cog):
|
||
"""Команда !cat — случайный котик"""
|
||
|
||
@commands.command(name="cat")
|
||
async def cat(self, ctx):
|
||
"""Получить случайного котика"""
|
||
try:
|
||
response = requests.get(
|
||
"https://api.thecatapi.com/v1/images/search",
|
||
timeout=10
|
||
)
|
||
response.raise_for_status()
|
||
data = response.json()
|
||
url = data[0]["url"]
|
||
|
||
embed = discord.Embed(
|
||
title="🐱 Котик для тебя!",
|
||
color=discord.Color.orange()
|
||
)
|
||
embed.set_image(url=url)
|
||
await ctx.send(embed=embed)
|
||
except requests.RequestException:
|
||
await ctx.send("Не удалось получить котика. Попробуйте позже.")
|