From 814b0e79e91021aded2fc77d0231200a48334bd6 Mon Sep 17 00:00:00 2001 From: Omega Launcher Date: Fri, 12 Jun 2026 17:49:07 +0100 Subject: [PATCH] fix(support): remove core commands in setup before cog loads Remove Red's built-in contact and dm commands in setup() before the Support cog loads to prevent command registration conflicts. Commands are stored and restored in teardown() when the cog unloads. Co-Authored-By: Claude Sonnet 4.5 (1M context) --- support/__init__.py | 18 ++++++++++++++++++ support/support.py | 29 ++--------------------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/support/__init__.py b/support/__init__.py index 8d1cd6f..2daaefc 100644 --- a/support/__init__.py +++ b/support/__init__.py @@ -8,7 +8,25 @@ __red_end_user_data_statement__ = ( "conversation history, and user preferences." ) +# Store removed commands for restoration +_removed_commands = {} + async def setup(bot): + # Remove Red's built-in commands BEFORE loading the cog + for cmd_name in ["contact", "dm"]: + cmd = bot.get_command(cmd_name) + if cmd: + _removed_commands[cmd_name] = cmd + bot.remove_command(cmd_name) + cog = Support(bot) await bot.add_cog(cog) + + +async def teardown(bot): + # Restore Red's built-in commands when unloading + for cmd_name, cmd in _removed_commands.items(): + if cmd_name not in bot.all_commands: + bot.add_command(cmd) + _removed_commands.clear() diff --git a/support/support.py b/support/support.py index aae42af..6f645ed 100644 --- a/support/support.py +++ b/support/support.py @@ -153,40 +153,15 @@ class Support(commands.Cog): self.bot.add_view(self._control_view) self._cleanup_task: Optional[asyncio.Task] = None - self._disabled_core_commands = [] async def cog_load(self): - """Start background tasks and disable core commands on cog load.""" + """Start background tasks on cog load.""" self._cleanup_task = asyncio.create_task(self._thread_cleanup_loop()) - await self._disable_core_commands() async def cog_unload(self): - """Clean up and re-enable core commands on unload.""" + """Clean up on unload.""" if self._cleanup_task: self._cleanup_task.cancel() - await self._enable_core_commands() - - async def _disable_core_commands(self): - """Disable Red's built-in contact and dm commands.""" - core_cog = self.bot.get_cog("Core") - if not core_cog: - return - - commands_to_disable = ["contact", "dm"] - - for cmd_name in commands_to_disable: - cmd = self.bot.get_command(cmd_name) - if cmd and cmd.cog_name == "Core": - cmd.enabled = False - self._disabled_core_commands.append(cmd_name) - - async def _enable_core_commands(self): - """Re-enable Red's core commands when this cog unloads.""" - for cmd_name in self._disabled_core_commands: - cmd = self.bot.get_command(cmd_name) - if cmd: - cmd.enabled = True - self._disabled_core_commands.clear() # ── Data Management ────────────────────────────────────────────────────── async def red_delete_data_for_user(self, *, requester: Literal["discord", "owner", "user", "user_strict"], user_id: int):