# example cog to make file less long purposes import discord, aiohttp from discord.ext import commands from utils.paginate import Paginator class example(commands.Cog): def __init__(self, bot): self.bot = bot @commands.hybrid_command(name="urbandictionary", aliases=["urban", "ud"], description="Get the definition of a word from Urban Dictionary.") async def urbandictionary(self, ctx: commands.Context, *, word: str): url = f"https://api.urbandictionary.com/v0/define?term={word}" async with aiohttp.ClientSession() as session: async with session.get(url) as response: if response.status != 200: await ctx.send("Failed to retrieve definition from Urban Dictionary.") return data = await response.json() if not data['list']: await ctx.send(f"No definition found for `{word}` on Urban Dictionary.") return pages = [] for entry in data['list']: title = f"[{entry['word']}]({entry['permalink']})" embed = discord.Embed( title=title, description=entry['definition'], color=0x2E51A2 ) embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar.url) embed.add_field(name="Example", value=entry['example'], inline=False) embed.add_field(name="Votes", value=f"👍 {entry['thumbs_up']} / 👎 {entry['thumbs_down']}", inline=False) pages.append(embed) paginator = Paginator(self.bot, ctx, pages) message = await ctx.send(embed=pages[0], view=paginator) paginator.message = message async def setup(bot): await bot.add_cog(example(bot))