62
62
)
63
63
64
64
if TYPE_CHECKING :
65
- pass
65
+ from .. interactions import Interaction
66
66
67
67
def wrap_callback (coro ):
68
68
@functools .wraps (coro )
@@ -99,7 +99,7 @@ class _BaseCommand:
99
99
100
100
class ApplicationCommand (_BaseCommand ):
101
101
cog = None
102
-
102
+
103
103
def __repr__ (self ):
104
104
return f"<discord.commands.{ self .__class__ .__name__ } name={ self .name } >"
105
105
@@ -143,8 +143,8 @@ async def can_run(self, ctx: ApplicationContext) -> bool:
143
143
# since we have no checks, then we just return True.
144
144
return True
145
145
146
- return await async_all (predicate (ctx ) for predicate in predicates ) # type: ignore
147
-
146
+ return await async_all (predicate (ctx ) for predicate in predicates ) # type: ignore
147
+
148
148
async def dispatch_error (self , ctx : ApplicationContext , error : Exception ) -> None :
149
149
ctx .command_failed = True
150
150
cog = self .cog
@@ -349,7 +349,7 @@ class SlashCommand(ApplicationCommand):
349
349
350
350
.. note::
351
351
352
- If this is not empty then default_permissions will be set to False.
352
+ If this is not empty then default_permissions will be set to False.
353
353
354
354
cog: Optional[:class:`Cog`]
355
355
The cog that this command belongs to. ``None`` if there isn't one.
@@ -515,8 +515,13 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
515
515
<= op .input_type .value
516
516
<= SlashCommandOptionType .role .value
517
517
):
518
- name = "member" if op .input_type .name == "user" else op .input_type .name
519
- arg = await get_or_fetch (ctx .guild , name , int (arg ), default = int (arg ))
518
+ if ctx .guild is None and op .input_type .name == "user" :
519
+ _data = ctx .interaction .data ["resolved" ]["users" ][arg ]
520
+ _data ["id" ] = int (arg )
521
+ arg = User (state = ctx .interaction ._state , data = _data )
522
+ else :
523
+ name = "member" if op .input_type .name == "user" else op .input_type .name
524
+ arg = await get_or_fetch (ctx .guild , name , int (arg ), default = int (arg ))
520
525
521
526
elif op .input_type == SlashCommandOptionType .mentionable :
522
527
arg_id = int (arg )
@@ -532,7 +537,7 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
532
537
for o in self .options :
533
538
if o ._parameter_name not in kwargs :
534
539
kwargs [o ._parameter_name ] = o .default
535
-
540
+
536
541
if self .cog is not None :
537
542
await self .callback (self .cog , ctx , ** kwargs )
538
543
elif self .parent is not None and self .attached_to_group is True :
@@ -542,12 +547,12 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
542
547
543
548
async def invoke_autocomplete_callback (self , ctx : AutocompleteContext ):
544
549
values = { i .name : i .default for i in self .options }
545
-
550
+
546
551
for op in ctx .interaction .data .get ("options" , []):
547
552
if op .get ("focused" , False ):
548
553
option = find (lambda o : o .name == op ["name" ], self .options )
549
554
values .update ({
550
- i ["name" ]:i ["value" ]
555
+ i ["name" ]:i ["value" ]
551
556
for i in ctx .interaction .data ["options" ]
552
557
})
553
558
ctx .command = self
@@ -657,7 +662,7 @@ def __init__(
657
662
658
663
self .min_value : minmax_typehint = kwargs .pop ("min_value" , None )
659
664
self .max_value : minmax_typehint = kwargs .pop ("max_value" , None )
660
-
665
+
661
666
if not (isinstance (self .min_value , minmax_types ) or self .min_value is None ):
662
667
raise TypeError (f"Expected { minmax_typehint } for min_value, got \" { type (self .min_value ).__name__ } \" " )
663
668
if not (isinstance (self .max_value , minmax_types ) or self .min_value is None ):
@@ -971,7 +976,7 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
971
976
self .checks = checks
972
977
self ._before_invoke = None
973
978
self ._after_invoke = None
974
-
979
+
975
980
self .validate_parameters ()
976
981
977
982
# Context Menu commands don't have permissions
@@ -1013,7 +1018,7 @@ def validate_parameters(self):
1013
1018
)
1014
1019
except StopIteration :
1015
1020
pass
1016
-
1021
+
1017
1022
def qualified_name (self ):
1018
1023
return self .name
1019
1024
@@ -1052,7 +1057,7 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
1052
1057
guild = ctx .interaction ._state ._get_guild (ctx .interaction .guild_id ),
1053
1058
state = ctx .interaction ._state ,
1054
1059
)
1055
-
1060
+
1056
1061
if self .cog is not None :
1057
1062
await self .callback (self .cog , ctx , target )
1058
1063
else :
@@ -1118,12 +1123,12 @@ async def _invoke(self, ctx: ApplicationContext):
1118
1123
channel = ctx .interaction ._state .add_dm_channel (data )
1119
1124
1120
1125
target = Message (state = ctx .interaction ._state , channel = channel , data = message )
1121
-
1126
+
1122
1127
if self .cog is not None :
1123
1128
await self .callback (self .cog , ctx , target )
1124
1129
else :
1125
1130
await self .callback (ctx , target )
1126
-
1131
+
1127
1132
def copy (self ):
1128
1133
"""Creates a copy of this command.
1129
1134
0 commit comments