mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-03 08:35:53 +00:00
[commands] Add initial implementation of hybrid commands
Hybrid commands allow a regular command to also double as a slash command, assuming it meets the subset required to function.
This commit is contained in:
@ -239,6 +239,9 @@ class Cog(metaclass=CogMeta):
|
||||
|
||||
lookup = {cmd.qualified_name: cmd for cmd in self.__cog_commands__}
|
||||
|
||||
# Register the application commands
|
||||
children: List[Union[app_commands.Group, app_commands.Command[Self, ..., Any]]] = []
|
||||
|
||||
# Update the Command instances dynamically as well
|
||||
for command in self.__cog_commands__:
|
||||
setattr(self, command.callback.__name__, command)
|
||||
@ -250,9 +253,12 @@ class Cog(metaclass=CogMeta):
|
||||
# Update our parent's reference to our self
|
||||
parent.remove_command(command.name) # type: ignore
|
||||
parent.add_command(command) # type: ignore
|
||||
elif cls.__cog_is_app_commands_group__:
|
||||
if hasattr(command, '__commands_is_hybrid__') and command.parent is None:
|
||||
# In both of these, the type checker does not see the app_command attribute even though it exists
|
||||
command.app_command = command.app_command._copy_with(parent=self, binding=self) # type: ignore
|
||||
children.append(command.app_command) # type: ignore
|
||||
|
||||
# Register the application commands
|
||||
children: List[Union[app_commands.Group, app_commands.Command[Self, ..., Any]]] = []
|
||||
for command in cls.__cog_app_commands__:
|
||||
copy = command._copy_with(
|
||||
# Type checker doesn't understand this type of narrowing.
|
||||
|
Reference in New Issue
Block a user