Skip to content

Commit ec23430

Browse files
committed
Fixed issues with subcommand
1 parent 5d5adf4 commit ec23430

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

dico_command/addon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init_subclass__(cls, **kwargs):
4444
def __init__(self, bot: "Bot"):
4545
self.bot = bot
4646
resp = [getattr(self, x) for x in dir(self)]
47-
self.commands: typing.List[Command] = [x for x in resp if isinstance(x, Command)]
47+
self.commands: typing.List[Command] = [x for x in resp if isinstance(x, Command) and not x.is_subcommand]
4848
self.listeners: typing.List[Listener] = [x for x in resp if isinstance(x, Listener)]
4949
self.interactions: typing.List["InteractionCommand"] = [x for x in resp if InteractionCommand is not None and isinstance(x, InteractionCommand)]
5050
self.callbacks: typing.List["ComponentCallback"] = [x for x in resp if ComponentCallback is not None and isinstance(x, ComponentCallback)]

dico_command/bot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ def __init__(self,
3232
self.addon_names: typing.List[str] = []
3333
self.modules: typing.List[str] = []
3434

35+
async def get_owners(self) -> typing.List[dico.Snowflake]:
36+
if not self.application:
37+
await self.request_current_bot_application_information()
38+
return self.application.owner_ids if self.application.owner_ids else [self.application.owner.id]
39+
3540
async def verify_prefix(self, message: dico.Message):
3641
final_prefixes = [(await x(message)) if is_coro(x) else x(message) if inspect.isfunction(x) else x for x in self.prefixes]
3742
prefix_result = [*map(lambda x: message.content.startswith(x), final_prefixes)]

dico_command/command.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def __init__(self,
99
func,
1010
name: str,
1111
checks: typing.Optional[typing.List[typing.Callable[[Context], bool]]] = None,
12-
aliases: typing.Optional[typing.List[str]] = None):
12+
aliases: typing.Optional[typing.List[str]] = None,
13+
is_subcommand: bool = False):
1314
self.func = func
1415
self.name = name
1516
self.checks = checks or []
@@ -21,16 +22,20 @@ def __init__(self,
2122
if hasattr(func, "_checks"):
2223
self.checks.extend(func._checks)
2324
self.addon = None
25+
self.is_subcommand = is_subcommand
2426

2527
def subcommand(self, *args, **kwargs):
2628
def wrap(coro):
2729
cmd = command(*args, **kwargs)(coro)
30+
cmd.is_subcommand = True
2831
self.subcommands[cmd.name] = cmd
2932
return cmd
3033
return wrap
3134

3235
def register_addon(self, addon):
3336
self.addon = addon
37+
for x in self.subcommands.values():
38+
x.register_addon(addon)
3439

3540
async def execute_error_handler(self, ctx, ex):
3641
if not self.error_handler:

0 commit comments

Comments
 (0)