diff --git a/interactions/client/bot.py b/interactions/client/bot.py index 838904c12..f1b2f2820 100644 --- a/interactions/client/bot.py +++ b/interactions/client/bot.py @@ -497,17 +497,18 @@ def __resolve_commands(self) -> None: ) data: Union[dict, List[dict]] = cmd.full_data - coro = cmd.dispatcher + dispatcher = cmd.dispatcher self.__check_command( command=ApplicationCommand(**(data[0] if isinstance(data, list) else data)), - coro=coro, + coro=dispatcher, ) if cmd.autocompletions: self.__id_autocomplete.update(cmd.autocompletions) - coro = coro.__func__ if hasattr(coro, "__func__") else coro + # weird interaction with methods, where they're a read-only version of their function + coro = dispatcher.__func__ if hasattr(dispatcher, "__func__") else dispatcher coro._command_data = data coro._name = cmd.name @@ -529,7 +530,7 @@ def __resolve_commands(self) -> None: else: self._scopes.add(cmd.scope if isinstance(cmd.scope, int) else cmd.scope.id) - self.event(coro, name=f"command_{cmd.name}") + self.event(dispatcher, name=f"command_{cmd.name}") cmd.resolved = True async def __sync(self) -> None: # sourcery no-metrics @@ -1584,7 +1585,6 @@ def __new__(cls, client: Client, *args, **kwargs) -> "Extension": commands = self._commands.get(cmd.name, []) coro = cmd.dispatcher - coro = coro.__func__ if hasattr(coro, "__func__") else coro commands.append(coro) self._commands[f"command_{cmd.name}"] = commands diff --git a/interactions/client/models/command.py b/interactions/client/models/command.py index 5ad7d3006..c326dc641 100644 --- a/interactions/client/models/command.py +++ b/interactions/client/models/command.py @@ -702,58 +702,57 @@ def decorator(coro: Callable[..., Awaitable]) -> "Command": return decorator - @property - def dispatcher(self) -> Callable[..., Awaitable]: - """ - Returns a coroutine that calls the command along with the subcommands, if any. - - .. note:: - The coroutine returned is never the same object. - - :return: A coroutine that calls the command along with the subcommands, if any. - :rtype: Callable[..., Awaitable] + async def dispatcher( + self, + ctx: "CommandContext", + *args, + sub_command_group: Optional[str] = None, + sub_command: Optional[str] = None, + **kwargs, + ) -> Optional[BaseResult]: + r""" + Call the command along with any subcommands + + :param ctx: The context for the interaction + :type ctx: CommandContext + :param args: The args to be passed to the command + :type args: tuple + :param sub_command_group: The subcommand group being invoked, if any + :type sub_command_group: Optional[str] + :param sub_command: The subcommand being invoked, if any + :type sub_command: Optional[str] + :param kwargs: The kwargs to pass to the command + :type kwargs: Dict + :return: The result of the base command if no StopCommand is returned anywhere, else None + :rtype: Optional[BaseResult] """ - if not self.has_subcommands: - return self.__wrap_coro(self.coro) - - @wraps(self.coro) - async def dispatch( - ctx: "CommandContext", - *args, - sub_command_group: Optional[str] = None, - sub_command: Optional[str] = None, - **kwargs, - ) -> Optional[Any]: - """Dispatches all of the subcommands of the command.""" - base_coro = self.coro - base_res = BaseResult( - result=await self.__call(base_coro, ctx, *args, _name=self.name, **kwargs) + base_coro = self.coro + base_res = BaseResult( + result=await self.__call(base_coro, ctx, *args, _name=self.name, **kwargs) + ) + if base_res() is StopCommand or isinstance(base_res(), StopCommand): + return + if sub_command_group: + group_coro = self.coroutines[sub_command_group] + name = f"{sub_command_group} {sub_command}" + subcommand_coro = self.coroutines[name] + group_res = GroupResult( + result=await self.__call( + group_coro, ctx, *args, _res=base_res, _name=sub_command_group, **kwargs + ), + parent=base_res, ) - if base_res() is StopCommand or isinstance(base_res(), StopCommand): + if group_res() is StopCommand or isinstance(group_res(), StopCommand): return - if sub_command_group: - group_coro = self.coroutines[sub_command_group] - name = f"{sub_command_group} {sub_command}" - subcommand_coro = self.coroutines[name] - group_res = GroupResult( - result=await self.__call( - group_coro, ctx, *args, _res=base_res, _name=sub_command_group, **kwargs - ), - parent=base_res, - ) - if group_res() is StopCommand or isinstance(group_res(), StopCommand): - return - return await self.__call( - subcommand_coro, ctx, *args, _res=group_res, _name=name, **kwargs - ) - elif sub_command: - subcommand_coro = self.coroutines[sub_command] - return await self.__call( - subcommand_coro, ctx, *args, _res=base_res, _name=sub_command, **kwargs - ) - return base_res - - return dispatch + return await self.__call( + subcommand_coro, ctx, *args, _res=group_res, _name=name, **kwargs + ) + elif sub_command: + subcommand_coro = self.coroutines[sub_command] + return await self.__call( + subcommand_coro, ctx, *args, _res=base_res, _name=sub_command, **kwargs + ) + return base_res def autocomplete( self, name: Optional[str] = MISSING