63
63
from ..role import Role
64
64
from ..threads import Thread
65
65
from ..user import User
66
- from ..utils import async_all , find , utcnow , maybe_coroutine
66
+ from ..utils import async_all , find , utcnow , maybe_coroutine , MISSING
67
67
from .context import ApplicationContext , AutocompleteContext
68
68
from .options import Option , OptionChoice
69
69
@@ -186,6 +186,7 @@ def __init__(self, func: Callable, **kwargs) -> None:
186
186
buckets = cooldown
187
187
else :
188
188
raise TypeError ("Cooldown must be a an instance of CooldownMapping or None." )
189
+
189
190
self ._buckets : CooldownMapping = buckets
190
191
191
192
max_concurrency = getattr (func , "__commands_max_concurrency__" , kwargs .get ("max_concurrency" ))
@@ -646,13 +647,7 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
646
647
647
648
self .attached_to_group : bool = False
648
649
649
- self .cog = None
650
-
651
- params = self ._get_signature_parameters ()
652
- if kwop := kwargs .get ("options" , None ):
653
- self .options : List [Option ] = self ._match_option_param_names (params , kwop )
654
- else :
655
- self .options : List [Option ] = self ._parse_options (params )
650
+ self .options : List [Option ] = kwargs .get ("options" , [])
656
651
657
652
try :
658
653
checks = func .__commands_checks__
@@ -665,13 +660,21 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
665
660
self ._before_invoke = None
666
661
self ._after_invoke = None
667
662
663
+ self ._cog = MISSING
664
+
665
+ def _validate_parameters (self ):
666
+ params = self ._get_signature_parameters ()
667
+ if kwop := self .options :
668
+ self .options : List [Option ] = self ._match_option_param_names (params , kwop )
669
+ else :
670
+ self .options : List [Option ] = self ._parse_options (params )
671
+
668
672
def _check_required_params (self , params ):
669
673
params = iter (params .items ())
670
674
required_params = (
671
675
["self" , "context" ]
672
676
if self .attached_to_group
673
677
or self .cog
674
- or len (self .callback .__qualname__ .split ("." )) > 1
675
678
else ["context" ]
676
679
)
677
680
for p in required_params :
@@ -764,6 +767,15 @@ def _is_typing_union(self, annotation):
764
767
def _is_typing_optional (self , annotation ):
765
768
return self ._is_typing_union (annotation ) and type (None ) in annotation .__args__ # type: ignore
766
769
770
+ @property
771
+ def cog (self ):
772
+ return self ._cog
773
+
774
+ @cog .setter
775
+ def cog (self , val ):
776
+ self ._cog = val
777
+ self ._validate_parameters ()
778
+
767
779
@property
768
780
def is_subcommand (self ) -> bool :
769
781
return self .parent is not None
@@ -956,6 +968,10 @@ def _update_copy(self, kwargs: Dict[str, Any]):
956
968
else :
957
969
return self .copy ()
958
970
971
+ def _set_cog (self , cog ):
972
+ super ()._set_cog (cog )
973
+ self ._validate_parameters ()
974
+
959
975
960
976
class SlashCommandGroup (ApplicationCommand ):
961
977
r"""A class that implements the protocol for a slash command group.
0 commit comments