import discord from discord import app_commands from discord.ext import commands from discord.ext.commands import Context class CogManagement(commands.Cog, name="cog_management"): def __init__(self, bot) -> None: self.bot = bot @commands.hybrid_command( name="load", description="Load a cog", ) @app_commands.describe(cog="The name of the cog to load") @commands.is_owner() async def load(self, context: Context, cog: str) -> None: """ The bot will load the given cog. :param context: The hybrid command context. :param cog: The name of the cog to load. """ try: await self.bot.load_extension(f"cogs.{cog}") except Exception: embed = discord.Embed( description=f"Could not load the `{cog}` cog.", color=0xE02B2B ) await context.send(embed=embed) return embed = discord.Embed( description=f"Successfully loaded the `{cog}` cog.", color=0xBEBEFE ) await context.send(embed=embed) @commands.hybrid_command( name="unload", description="Unloads a cog.", ) @app_commands.describe(cog="The name of the cog to unload") @commands.is_owner() async def unload(self, context: Context, cog: str) -> None: """ The bot will unload the given cog. :param context: The hybrid command context. :param cog: The name of the cog to unload. """ try: await self.bot.unload_extension(f"cogs.{cog}") except Exception: embed = discord.Embed( description=f"Could not unload the `{cog}` cog.", color=0xE02B2B ) await context.send(embed=embed) return embed = discord.Embed( description=f"Successfully unloaded the `{cog}` cog.", color=0xBEBEFE ) await context.send(embed=embed) @commands.hybrid_command( name="reload", description="Reloads a cog.", ) @app_commands.describe(cog="The name of the cog to reload") @commands.is_owner() async def reload(self, context: Context, cog: str) -> None: """ The bot will reload the given cog. :param context: The hybrid command context. :param cog: The name of the cog to reload. """ try: await self.bot.reload_extension(f"cogs.{cog}") except Exception: embed = discord.Embed( description=f"Could not reload the `{cog}` cog.", color=0xE02B2B ) await context.send(embed=embed) return embed = discord.Embed( description=f"Successfully reloaded the `{cog}` cog.", color=0xBEBEFE ) await context.send(embed=embed) async def setup(bot) -> None: await bot.add_cog(CogManagement(bot))