Files
Syntrel/cogs/fun/randomfact.py

30 lines
1.2 KiB
Python
Raw Normal View History

2025-09-14 18:54:56 -04:00
import aiohttp
import discord
from discord.ext import commands
def randomfact_command():
2025-09-14 18:54:56 -04:00
@commands.hybrid_command(name="randomfact", description="Get a random fact.")
async def randomfact(self, context):
2025-09-14 18:54:56 -04:00
async with aiohttp.ClientSession() as session:
async with session.get(
"https://uselessfacts.jsph.pl/random.json?language=en"
) as request:
if request.status == 200:
data = await request.json()
embed = discord.Embed(
title="Random Fact",
description=data["text"],
color=0x7289DA
)
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
2025-09-14 18:54:56 -04:00
else:
embed = discord.Embed(
title="Error!",
description="There is something wrong with the API, please try again later",
color=0xE02B2B,
)
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
2025-09-14 18:54:56 -04:00
await context.send(embed=embed)
return randomfact