@@ -702,58 +702,57 @@ def decorator(coro: Callable[..., Awaitable]) -> "Command":
702
702
703
703
return decorator
704
704
705
- @property
706
- def dispatcher (self ) -> Callable [..., Awaitable ]:
707
- """
708
- Returns a coroutine that calls the command along with the subcommands, if any.
709
-
710
- .. note::
711
- The coroutine returned is never the same object.
712
-
713
- :return: A coroutine that calls the command along with the subcommands, if any.
714
- :rtype: Callable[..., Awaitable]
705
+ async def dispatcher (
706
+ self ,
707
+ ctx : "CommandContext" ,
708
+ * args ,
709
+ sub_command_group : Optional [str ] = None ,
710
+ sub_command : Optional [str ] = None ,
711
+ ** kwargs ,
712
+ ) -> Optional [BaseResult ]:
713
+ r"""
714
+ Call the command along with any subcommands
715
+
716
+ :param ctx: The context for the interaction
717
+ :type ctx: CommandContext
718
+ :param args: The args to be passed to the command
719
+ :type args: tuple
720
+ :param sub_command_group: The subcommand group being invoked, if any
721
+ :type sub_command_group: Optional[str]
722
+ :param sub_command: The subcommand being invoked, if any
723
+ :type sub_command: Optional[str]
724
+ :param kwargs: The kwargs to pass to the command
725
+ :type kwargs: Dict
726
+ :return: The result of the base command if no StopCommand is returned anywhere, else None
727
+ :rtype: Optional[BaseResult]
715
728
"""
716
- if not self .has_subcommands :
717
- return self . __wrap_coro ( self . coro )
718
-
719
- @ wraps ( self . coro )
720
- async def dispatch (
721
- ctx : "CommandContext" ,
722
- * args ,
723
- sub_command_group : Optional [ str ] = None ,
724
- sub_command : Optional [ str ] = None ,
725
- ** kwargs ,
726
- ) -> Optional [ Any ]:
727
- """Dispatches all of the subcommands of the command."""
728
- base_coro = self . coro
729
- base_res = BaseResult (
730
- result = await self . __call ( base_coro , ctx , * args , _name = self . name , ** kwargs )
729
+ base_coro = self .coro
730
+ base_res = BaseResult (
731
+ result = await self . __call ( base_coro , ctx , * args , _name = self . name , ** kwargs )
732
+ )
733
+ if base_res () is StopCommand or isinstance ( base_res (), StopCommand ):
734
+ return
735
+ if sub_command_group :
736
+ group_coro = self . coroutines [ sub_command_group ]
737
+ name = f" { sub_command_group } { sub_command } "
738
+ subcommand_coro = self . coroutines [ name ]
739
+ group_res = GroupResult (
740
+ result = await self . __call (
741
+ group_coro , ctx , * args , _res = base_res , _name = sub_command_group , ** kwargs
742
+ ),
743
+ parent = base_res ,
731
744
)
732
- if base_res () is StopCommand or isinstance (base_res (), StopCommand ):
745
+ if group_res () is StopCommand or isinstance (group_res (), StopCommand ):
733
746
return
734
- if sub_command_group :
735
- group_coro = self .coroutines [sub_command_group ]
736
- name = f"{ sub_command_group } { sub_command } "
737
- subcommand_coro = self .coroutines [name ]
738
- group_res = GroupResult (
739
- result = await self .__call (
740
- group_coro , ctx , * args , _res = base_res , _name = sub_command_group , ** kwargs
741
- ),
742
- parent = base_res ,
743
- )
744
- if group_res () is StopCommand or isinstance (group_res (), StopCommand ):
745
- return
746
- return await self .__call (
747
- subcommand_coro , ctx , * args , _res = group_res , _name = name , ** kwargs
748
- )
749
- elif sub_command :
750
- subcommand_coro = self .coroutines [sub_command ]
751
- return await self .__call (
752
- subcommand_coro , ctx , * args , _res = base_res , _name = sub_command , ** kwargs
753
- )
754
- return base_res
755
-
756
- return dispatch
747
+ return await self .__call (
748
+ subcommand_coro , ctx , * args , _res = group_res , _name = name , ** kwargs
749
+ )
750
+ elif sub_command :
751
+ subcommand_coro = self .coroutines [sub_command ]
752
+ return await self .__call (
753
+ subcommand_coro , ctx , * args , _res = base_res , _name = sub_command , ** kwargs
754
+ )
755
+ return base_res
757
756
758
757
def autocomplete (
759
758
self , name : Optional [str ] = MISSING
0 commit comments