29
29
import functools
30
30
import itertools
31
31
import re
32
- from typing import TYPE_CHECKING
32
+ from typing import TYPE_CHECKING , Any
33
33
34
34
import discord .utils
35
+ from discord .ext import bridge
35
36
36
37
from .core import Command , Group
37
38
from .errors import CommandError
@@ -550,7 +551,9 @@ def subcommand_not_found(self, command, string):
550
551
)
551
552
return f'Command "{ command .qualified_name } " has no subcommands.'
552
553
553
- async def filter_commands (self , commands , * , sort = False , key = None ):
554
+ async def filter_commands (
555
+ self , commands , * , sort = False , key = None , exclude : tuple [Any ] | None = None
556
+ ):
554
557
"""|coro|
555
558
556
559
Returns a filtered list of commands and optionally sorts them.
@@ -568,6 +571,8 @@ async def filter_commands(self, commands, *, sort=False, key=None):
568
571
An optional key function to pass to :func:`py:sorted` that
569
572
takes a :class:`Command` as its sole parameter. If ``sort`` is
570
573
passed as ``True`` then this will default as the command name.
574
+ exclude: Optional[Tuple[Any, ...]]
575
+ A tuple of command types to exclude from the filter.
571
576
572
577
Returns
573
578
-------
@@ -579,15 +584,18 @@ async def filter_commands(self, commands, *, sort=False, key=None):
579
584
key = lambda c : c .name
580
585
581
586
# Ignore Application Commands because they don't have hidden/docs
582
- prefix_commands = [
587
+ new_commands = [
583
588
command
584
589
for command in commands
585
- if not isinstance (command , discord .commands .ApplicationCommand )
590
+ if not isinstance (
591
+ command ,
592
+ (discord .commands .ApplicationCommand , * (exclude if exclude else ())),
593
+ )
586
594
]
587
595
iterator = (
588
- prefix_commands
596
+ new_commands
589
597
if self .show_hidden
590
- else filter (lambda c : not c .hidden , prefix_commands )
598
+ else filter (lambda c : not c .hidden , new_commands )
591
599
)
592
600
593
601
if self .verify_checks is False :
@@ -1107,7 +1115,9 @@ async def send_cog_help(self, cog):
1107
1115
self .paginator .add_line (cog .description , empty = True )
1108
1116
1109
1117
filtered = await self .filter_commands (
1110
- cog .get_commands (), sort = self .sort_commands
1118
+ cog .get_commands (),
1119
+ sort = self .sort_commands ,
1120
+ exclude = (bridge .BridgeExtCommand ,),
1111
1121
)
1112
1122
self .add_indented_commands (filtered , heading = self .commands_heading )
1113
1123
@@ -1357,7 +1367,9 @@ async def send_cog_help(self, cog):
1357
1367
self .paginator .add_line (cog .description , empty = True )
1358
1368
1359
1369
filtered = await self .filter_commands (
1360
- cog .get_commands (), sort = self .sort_commands
1370
+ cog .get_commands (),
1371
+ sort = self .sort_commands ,
1372
+ exclude = (bridge .BridgeExtCommand ,),
1361
1373
)
1362
1374
if filtered :
1363
1375
self .paginator .add_line (f"**{ cog .qualified_name } { self .commands_heading } **" )
0 commit comments