Skip to content

Commit e566d1e

Browse files
authored
fix: properly parse aliases for base commands (#1728)
* fix: properly parse aliases for base commands * fix: don't add random aliases to base commands
1 parent d5dfe8e commit e566d1e

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

interactions/client/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,9 @@ def add_command(self, func: Callable) -> None:
14891489
elif not isinstance(func, BaseCommand):
14901490
raise TypeError("Invalid command type")
14911491

1492+
for hook in self._add_command_hook:
1493+
hook(func)
1494+
14921495
if not func.callback:
14931496
# for group = SlashCommand(...) usage
14941497
return
@@ -1499,9 +1502,6 @@ def add_command(self, func: Callable) -> None:
14991502
else:
15001503
self.logger.debug(f"Added callback: {func.callback.__name__}")
15011504

1502-
for hook in self._add_command_hook:
1503-
hook(func)
1504-
15051505
self.dispatch(CallbackAdded(callback=func, extension=func.extension if hasattr(func, "extension") else None))
15061506

15071507
def _gather_callbacks(self) -> None:

interactions/ext/hybrid_commands/manager.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,27 @@ def _add_hybrid_command(self, callback: Callable):
8181
return
8282

8383
cmd = callback
84+
85+
if not cmd.callback or cmd._dummy_base:
86+
if cmd.group_name:
87+
if not (group := self.client.prefixed.get_command(f"{cmd.name} {cmd.group_name}")):
88+
group = base_subcommand_generator(
89+
str(cmd.group_name),
90+
list(_values_wrapper(cmd.group_name.to_locale_dict())) + cmd.aliases,
91+
str(cmd.group_name),
92+
group=True,
93+
)
94+
self.client.prefixed.commands[str(cmd.name)].add_command(group)
95+
elif not (base := self.client.prefixed.commands.get(str(cmd.name))):
96+
base = base_subcommand_generator(
97+
str(cmd.name),
98+
list(_values_wrapper(cmd.name.to_locale_dict())) + cmd.aliases,
99+
str(cmd.name),
100+
group=False,
101+
)
102+
self.client.prefixed.add_command(base)
103+
return
104+
84105
prefixed_transform = slash_to_prefixed(cmd)
85106

86107
if self.use_slash_command_msg:
@@ -91,7 +112,7 @@ def _add_hybrid_command(self, callback: Callable):
91112
if not (base := self.client.prefixed.commands.get(str(cmd.name))):
92113
base = base_subcommand_generator(
93114
str(cmd.name),
94-
list(_values_wrapper(cmd.name.to_locale_dict())) + cmd.aliases,
115+
list(_values_wrapper(cmd.name.to_locale_dict())),
95116
str(cmd.name),
96117
group=False,
97118
)
@@ -102,7 +123,7 @@ def _add_hybrid_command(self, callback: Callable):
102123
if not (group := base.subcommands.get(str(cmd.group_name))):
103124
group = base_subcommand_generator(
104125
str(cmd.group_name),
105-
list(_values_wrapper(cmd.group_name.to_locale_dict())) + cmd.aliases,
126+
list(_values_wrapper(cmd.group_name.to_locale_dict())),
106127
str(cmd.group_name),
107128
group=True,
108129
)

0 commit comments

Comments
 (0)