From f08cb453ecaecaa46af0b1db376686eecdb6d4fc Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Fri, 23 Oct 2026 21:34:37 +0200 Subject: [PATCH] stop reloadall and reloadunloaded failing on unloaded cogs Co-Authored-By: Claude Opus 5.5 --- bot/src/cogs/dev_tools.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/bot/src/cogs/dev_tools.py b/bot/src/cogs/dev_tools.py index e053baa..0bdce49 100644 --- a/bot/src/cogs/dev_tools.py +++ b/bot/src/cogs/dev_tools.py @@ -191,17 +191,14 @@ class DevTools(commands.Cog): ctx (commands.Context): Context object """ - # Unload all cogs + # Unloading or reloading a cog that isn't loaded raises an error, so those are loaded instead for file in listdir("./src/cogs"): if file.endswith(".py"): - name = file[:-3] - await self.bot.unload_extension(f"cogs.{name}") - - # Load all cogs - for file in listdir("./src/cogs"): - if file.endswith(".py"): - name = file[:-3] - await self.bot.load_extension(f"cogs.{name}") + name = f"cogs.{file[:-3]}" + if name in self.bot.extensions: + await self.bot.reload_extension(name) + else: + await self.bot.load_extension(name) embed = discord.Embed(color=ctx.me.color, description="Reloaded all cogs") await ctx.reply(embed=embed) @@ -216,10 +213,9 @@ class DevTools(commands.Cog): ctx (commands.Context): Context object """ - for file in listdir("./src/cogs"): - if file.endswith(".py"): - name = file[:-3] - await self.bot.reload_extension(f"cogs.{name}") + # Only loaded cogs can be reloaded. Copied to a list since reloading modifies bot.extensions + for name in list(self.bot.extensions): + await self.bot.reload_extension(name) embed = discord.Embed(color=ctx.me.color, description="Reloaded all previously enabled cogs") await ctx.reply(embed=embed)