Files
Syntrel/cogs/fun/randomfact.py
neoarz e7ee97074b refactor(fun): cogs into one group
Combined all fun commands into a single 'fun' GroupCog with subcommands, replacing individual cogs for coinflip, eightball, minesweeper, randomfact, and rockpaperscissors. Updated bot.py to load the fun cog as a package and adjusted help.py to reflect the new command structure. This improves organization and discoverability of fun commands.
2025-09-28 22:48:10 -04:00

30 lines
1.2 KiB
Python

import aiohttp
import discord
from discord.ext import commands
def randomfact_command():
@commands.hybrid_command(name="randomfact", description="Get a random fact.")
async def randomfact(self, context):
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")
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")
await context.send(embed=embed)
return randomfact