From 8b34f8a5819b72128294e042445ac2f10ffc5e3b Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 27 Nov 2024 14:20:07 +0100 Subject: [PATCH 1/4] :bug: Fix duplicate bridge cmds in default help cmd --- discord/ext/commands/help.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/discord/ext/commands/help.py b/discord/ext/commands/help.py index 25b44388bd..ff587c824c 100644 --- a/discord/ext/commands/help.py +++ b/discord/ext/commands/help.py @@ -32,6 +32,7 @@ from typing import TYPE_CHECKING import discord.utils +from discord.ext import bridge from .core import Command, Group from .errors import CommandError @@ -582,7 +583,9 @@ async def filter_commands(self, commands, *, sort=False, key=None): prefix_commands = [ command for command in commands - if not isinstance(command, discord.commands.ApplicationCommand) + if not isinstance( + command, (discord.commands.ApplicationCommand, bridge.BridgeExtCommand) + ) ] iterator = ( prefix_commands From 3497f230957a7bfdb2ab39d2eae202c025ac86b0 Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 27 Nov 2024 14:28:32 +0100 Subject: [PATCH 2/4] :memo: CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9547fbafc..57e7d7e105 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2624](https://github.com/Pycord-Development/pycord/pull/2624)) - Fixed `AttributeError` when accessing `Member.guild_permissions` for user installed apps. ([#2650](https://github.com/Pycord-Development/pycord/pull/2650)) +- Fixed `BridgeCommand` duplicate in default help command. + ([#2656](https://github.com/Pycord-Development/pycord/pull/2656)) ### Changed From 14ddc850389e077418fa2cd061f2e3f078b555e1 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 9 Dec 2024 10:50:23 +0100 Subject: [PATCH 3/4] :bug: Fix implementation --- discord/ext/commands/help.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/discord/ext/commands/help.py b/discord/ext/commands/help.py index ff587c824c..f417325306 100644 --- a/discord/ext/commands/help.py +++ b/discord/ext/commands/help.py @@ -29,7 +29,7 @@ import functools import itertools import re -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import discord.utils from discord.ext import bridge @@ -551,7 +551,9 @@ def subcommand_not_found(self, command, string): ) return f'Command "{command.qualified_name}" has no subcommands.' - async def filter_commands(self, commands, *, sort=False, key=None): + async def filter_commands( + self, commands, *, sort=False, key=None, exclude: tuple[Any] | None = None + ): """|coro| Returns a filtered list of commands and optionally sorts them. @@ -580,17 +582,18 @@ async def filter_commands(self, commands, *, sort=False, key=None): key = lambda c: c.name # Ignore Application Commands because they don't have hidden/docs - prefix_commands = [ + new_commands = [ command for command in commands if not isinstance( - command, (discord.commands.ApplicationCommand, bridge.BridgeExtCommand) + command, + (discord.commands.ApplicationCommand, *(exclude if exclude else ())), ) ] iterator = ( - prefix_commands + new_commands if self.show_hidden - else filter(lambda c: not c.hidden, prefix_commands) + else filter(lambda c: not c.hidden, new_commands) ) if self.verify_checks is False: @@ -1110,7 +1113,9 @@ async def send_cog_help(self, cog): self.paginator.add_line(cog.description, empty=True) filtered = await self.filter_commands( - cog.get_commands(), sort=self.sort_commands + cog.get_commands(), + sort=self.sort_commands, + exclude=(bridge.BridgeExtCommand,), ) self.add_indented_commands(filtered, heading=self.commands_heading) @@ -1360,7 +1365,9 @@ async def send_cog_help(self, cog): self.paginator.add_line(cog.description, empty=True) filtered = await self.filter_commands( - cog.get_commands(), sort=self.sort_commands + cog.get_commands(), + sort=self.sort_commands, + exclude=(bridge.BridgeExtCommand,), ) if filtered: self.paginator.add_line(f"**{cog.qualified_name} {self.commands_heading}**") From 9756f965959d8813e2016c117a7d84b0b66a0a6b Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 9 Dec 2024 11:43:35 +0100 Subject: [PATCH 4/4] :memo: Document `exclude` --- discord/ext/commands/help.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discord/ext/commands/help.py b/discord/ext/commands/help.py index f417325306..4c2f1ab9fd 100644 --- a/discord/ext/commands/help.py +++ b/discord/ext/commands/help.py @@ -571,6 +571,8 @@ async def filter_commands( An optional key function to pass to :func:`py:sorted` that takes a :class:`Command` as its sole parameter. If ``sort`` is passed as ``True`` then this will default as the command name. + exclude: Optional[Tuple[Any, ...]] + A tuple of command types to exclude from the filter. Returns -------