Create cogmanager.py

This commit is contained in:
WhatDidYouExpect 2025-01-05 20:35:47 +01:00 committed by GitHub
parent dcde62d774
commit 3487547720
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

54
cogmanager.py Normal file
View file

@ -0,0 +1,54 @@
import discord
from discord.ext import commands
import os
class CogManager(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.owner_id = int(os.getenv("ownerid"))
@commands.command()
async def load(self, ctx, cog_name: str = None):
if ctx.author.id != self.owner_id:
await ctx.send("You do not have permission to use this command.")
return
if cog_name is None:
await ctx.send("Please provide the cog name to load.")
return
try:
await self.bot.load_extension(f"cogs.{cog_name}")
await ctx.send(f"Loaded cog `{cog_name}` successfully.")
except Exception as e:
await ctx.send(f"Error loading cog `{cog_name}`: {e}")
@commands.command()
async def unload(self, ctx, cog_name: str = None):
if ctx.author.id != self.owner_id:
await ctx.send("You do not have permission to use this command.")
return
if cog_name is None:
await ctx.send("Please provide the cog name to unload.")
return
try:
await self.bot.unload_extension(f"cogs.{cog_name}")
await ctx.send(f"Unloaded cog `{cog_name}` successfully.")
except Exception as e:
await ctx.send(f"Error unloading cog `{cog_name}`: {e}")
@commands.command()
async def reload(self, ctx, cog_name: str = None):
if ctx.author.id != self.owner_id:
await ctx.send("You do not have permission to use this command.")
return
if cog_name is None:
await ctx.send("Please provide the cog name to reload.")
return
try:
await self.bot.unload_extension(f"cogs.{cog_name}")
await self.bot.load_extension(f"cogs.{cog_name}")
await ctx.send(f"Reloaded cog `{cog_name}` successfully.")
except Exception as e:
await ctx.send(f"Error reloading cog `{cog_name}`: {e}")
async def setup(bot):
await bot.add_cog(CogManager(bot))