Is There A Way To Find All The Loaded And Unloaded Cogs In Discord.py-rewrite
I have a lot of cogs for my bot, but i load and unload them using commands Still I get confused and load/unload a cog again-and-again I wonder is there a way to check all the loade
Solution 1:
Looking at discord.py documentation, if you try to load a cog that is already loaded,
it will raise a discord.ext.commands.ExtensionAlreadyLoaded
exception. Using this error, you could do this:
from discord import commands
bot = commands.Bot(command_prefix="!")
@bot.command()asyncdefcheck_cogs(ctx, cog_name):
try:
bot.load_extension(f"cogs.{cog_name}")
except commands.ExtensionAlreadyLoaded:
await ctx.send("Cog is loaded")
except commands.ExtensionNotFound:
await ctx.send("Cog not found")
else:
await ctx.send("Cog is unloaded")
bot.unload_extension(f"cogs.{cog_name}")
PS: your cogs will need to be in a cogs
folder for this code to work.
Post a Comment for "Is There A Way To Find All The Loaded And Unloaded Cogs In Discord.py-rewrite"