From 43371b45f3726317f089243636fb8b0a76f12a52 Mon Sep 17 00:00:00 2001 From: Karlo Prikratki Date: Sun, 30 Mar 2025 16:29:53 +0200 Subject: [PATCH 1/2] it will work first try --- redbot/core/core_commands.py | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 93cacdeb840..613be1716df 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -2257,6 +2257,67 @@ async def slash_disablecog(self, ctx: commands.Context, *cog_names: str): for page in pagify(output): await ctx.send(page) + @slash.command(name="disableall") + async def slash_disableall(self, ctx: commands.Context): + """Marks all application commands as being disabled, preventing them from being added to the bot. + This will not disable commands that are force-enabled by the cog creator. + + See a list of cogs with application commands with `[p]slash list`. + + This command does NOT sync the enabled commands with Discord, that must be done manually with `[p]slash sync` for commands to appear in users' clients. + """ + removed = [] + removed_cogs = int() + forced_commands = int() + for name, com in self.bot.tree._global_commands.items(): + if not com.extras.get("red_force_enable"): + await self.bot.disable_app_command(name, discord.AppCommandType.chat_input) + removed.append(name) + removed_cogs += 1 + else: + forced_commands += 1 + for key, com in self.bot.tree._context_menus.items(): + if not com.extras.get("red_force_enable"): + name, guild_id, com_type = key + await self.bot.disable_app_command(name, discord.AppCommandType(com_type)) + removed.append(name) + removed_cogs += 1 + else: + forced_commands += 1 + + if not removed: + output = _( + "Couldn't find any enabled commands. Use `{prefix}slash list` to see all cogs with application commands." + ).format( + prefix=ctx.clean_prefix, + ) + if forced_commands: + output += "\n" + output += _( + "There are {count} force-enabled commands that can't be disabled. They can be disabled only by unloading their cog.".format( + count=forced_commands + ) + ) + await ctx.send(output) + return + + await self.bot.tree.red_check_enabled() + formatted_names = humanize_list([inline(name) for name in removed]) + output = _("Disabled {count} commands:\n{names}").format( + count=len(removed), + names=formatted_names, + ) + if forced_commands: + output += "\n\n" + output += _( + "There are {count} force-enabled commands that were not disabled. To disable them, unload their cog.\nUse `{prefix}slash list` to see all cogs with application commands." + ).format( + count=forced_commands, + prefix=ctx.clean_prefix, + ) + for page in pagify(output): + await ctx.send(page) + @slash.command(name="list") async def slash_list(self, ctx: commands.Context): """List the slash commands the bot can see, and whether or not they are enabled. From 3e59e3a937ec4177daf3fdb960fee7d7fb7236f5 Mon Sep 17 00:00:00 2001 From: Karlo Prikratki Date: Sun, 30 Mar 2025 16:53:20 +0200 Subject: [PATCH 2/2] docs (it worked first try) --- docs/cog_guides/core.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/cog_guides/core.rst b/docs/cog_guides/core.rst index 28ccbe2069d..de4165b302b 100644 --- a/docs/cog_guides/core.rst +++ b/docs/cog_guides/core.rst @@ -4197,6 +4197,26 @@ with ``[p]slash sync`` for commands to appear in users' clients. **Arguments:** - ```` - The cogs to disable commands from. This argument is case sensitive. +.. _core-command-slash-disableall: + +"""""""""""""""" +slash disableall +"""""""""""""""" + +**Syntax** + +.. code-block:: none + + [p]slash disableall + +**Description** + +Marks all application commands as being disabled, preventing them from being added to the bot. +This will not disable commands that are force-enabled by the cog creator. +See a list of cogs with application commands with ``[p]slash list``. +This command does NOT sync the enabled commands with Discord, that must be done manually +with ``[p]slash sync`` for commands to appear in users' clients. + .. _core-command-slash-enable: """"""""""""