60
60
"MessageCommand" ,
61
61
)
62
62
63
- if TYPE_CHECKING :
63
+ if TYPE_CHECKING :
64
64
from ..interactions import Interaction
65
65
66
66
def wrap_callback (coro ):
@@ -98,7 +98,7 @@ class _BaseCommand:
98
98
99
99
class ApplicationCommand (_BaseCommand ):
100
100
cog = None
101
-
101
+
102
102
def __repr__ (self ):
103
103
return f"<discord.commands.{ self .__class__ .__name__ } name={ self .name } >"
104
104
@@ -142,8 +142,8 @@ async def can_run(self, ctx: ApplicationContext) -> bool:
142
142
# since we have no checks, then we just return True.
143
143
return True
144
144
145
- return await async_all (predicate (ctx ) for predicate in predicates ) # type: ignore
146
-
145
+ return await async_all (predicate (ctx ) for predicate in predicates ) # type: ignore
146
+
147
147
async def dispatch_error (self , ctx : ApplicationContext , error : Exception ) -> None :
148
148
ctx .command_failed = True
149
149
cog = self .cog
@@ -345,7 +345,7 @@ class SlashCommand(ApplicationCommand):
345
345
346
346
.. note::
347
347
348
- If this is not empty then default_permissions will be set to False.
348
+ If this is not empty then default_permissions will be set to False.
349
349
350
350
cog: Optional[:class:`Cog`]
351
351
The cog that this command belongs to. ``None`` if there isn't one.
@@ -504,8 +504,11 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
504
504
<= op .input_type .value
505
505
<= SlashCommandOptionType .role .value
506
506
):
507
- name = "member" if op .input_type .name == "user" else op .input_type .name
508
- arg = await get_or_fetch (ctx .guild , name , int (arg ), default = int (arg ))
507
+ if ctx .guild is None and op .input_type .name == "user" :
508
+ arg = User (state = ctx .interaction ._state , data = int (arg ))
509
+ else :
510
+ name = "member" if op .input_type .name == "user" else op .input_type .name
511
+ arg = await get_or_fetch (ctx .guild , name , int (arg ), default = int (arg ))
509
512
510
513
elif op .input_type == SlashCommandOptionType .mentionable :
511
514
arg_id = int (arg )
@@ -521,20 +524,20 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
521
524
for o in self .options :
522
525
if o ._parameter_name not in kwargs :
523
526
kwargs [o ._parameter_name ] = o .default
524
-
527
+
525
528
if self .cog is not None :
526
529
await self .callback (self .cog , ctx , ** kwargs )
527
530
else :
528
531
await self .callback (ctx , ** kwargs )
529
532
530
533
async def invoke_autocomplete_callback (self , interaction : Interaction ):
531
534
values = { i .name : i .default for i in self .options }
532
-
535
+
533
536
for op in interaction .data .get ("options" , []):
534
537
if op .get ("focused" , False ):
535
538
option = find (lambda o : o .name == op ["name" ], self .options )
536
539
values .update ({
537
- i ["name" ]:i ["value" ]
540
+ i ["name" ]:i ["value" ]
538
541
for i in interaction .data ["options" ]
539
542
})
540
543
ctx = AutocompleteContext (interaction , command = self , focused = option , value = op .get ("value" ), options = values )
@@ -631,15 +634,15 @@ def __init__(
631
634
632
635
self .min_value : minmax_typehint = kwargs .pop ("min_value" , None )
633
636
self .max_value : minmax_typehint = kwargs .pop ("max_value" , None )
634
-
637
+
635
638
if not (isinstance (self .min_value , minmax_types ) or self .min_value is None ):
636
639
raise TypeError (f"Expected { minmax_typehint } for min_value, got \" { type (self .min_value ).__name__ } \" " )
637
640
if not (isinstance (self .max_value , minmax_types ) or self .min_value is None ):
638
641
raise TypeError (f"Expected { minmax_typehint } for max_value, got \" { type (self .max_value ).__name__ } \" " )
639
642
640
643
self .autocomplete = kwargs .pop ("autocomplete" , None )
641
644
if (
642
- self .autocomplete and
645
+ self .autocomplete and
643
646
not asyncio .iscoroutinefunction (self .autocomplete )
644
647
):
645
648
raise TypeError ("Autocomplete callback must be a coroutine." )
@@ -848,7 +851,7 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
848
851
self .checks = checks
849
852
self ._before_invoke = None
850
853
self ._after_invoke = None
851
-
854
+
852
855
self .validate_parameters ()
853
856
854
857
# Context Menu commands don't have permissions
@@ -890,7 +893,7 @@ def validate_parameters(self):
890
893
)
891
894
except StopIteration :
892
895
pass
893
-
896
+
894
897
def qualified_name (self ):
895
898
return self .name
896
899
@@ -929,12 +932,12 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
929
932
guild = ctx .interaction ._state ._get_guild (ctx .interaction .guild_id ),
930
933
state = ctx .interaction ._state ,
931
934
)
932
-
935
+
933
936
if self .cog is not None :
934
937
await self .callback (self .cog , ctx , target )
935
938
else :
936
939
await self .callback (ctx , target )
937
-
940
+
938
941
def copy (self ):
939
942
"""Creates a copy of this command.
940
943
@@ -995,12 +998,12 @@ async def _invoke(self, ctx: ApplicationContext):
995
998
channel = ctx .interaction ._state .add_dm_channel (data )
996
999
997
1000
target = Message (state = ctx .interaction ._state , channel = channel , data = message )
998
-
1001
+
999
1002
if self .cog is not None :
1000
1003
await self .callback (self .cog , ctx , target )
1001
1004
else :
1002
1005
await self .callback (ctx , target )
1003
-
1006
+
1004
1007
def copy (self ):
1005
1008
"""Creates a copy of this command.
1006
1009
0 commit comments