Skip to content

Commit fcb263c

Browse files
committed
fix(application_commands): Fixed command checks not working
feat(application_commands): Added the ability to pass the values directly for slash command choices
1 parent cbf262a commit fcb263c

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

discord/application_commands.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -358,21 +358,24 @@ def _fill_data(self, data) -> ApplicationCommand:
358358
return self
359359

360360
async def can_run(self, *args, **kwargs) -> bool:
361+
#if self.cog:
362+
# args = (self.cog, *args)
361363
check_func = kwargs.pop('__func', self)
362364
checks = getattr(check_func, '__commands_checks__', getattr(self.func, '__commands_checks__', None))
363365
if not checks:
364366
return True
365-
366367
return await async_all(check(*args) for check in checks)
367368

368369
async def invoke(self, interaction, *args, **kwargs):
369-
if self.cog is not None:
370-
args = (self.cog, interaction, *args)
371-
else:
372-
args = (interaction, *args)
370+
if not self.func:
371+
return
372+
args = (interaction, *args)
373373
try:
374374
if await self.can_run(*args):
375-
await self.func(*args, **kwargs)
375+
if self.cog:
376+
await self.func(self.cog, *args, **kwargs)
377+
else:
378+
await self.func(*args, **kwargs)
376379
except Exception as exc:
377380
if hasattr(self, 'on_error'):
378381
if self.cog is not None:
@@ -840,8 +843,8 @@ def to_dict(self):
840843
return base
841844

842845
async def can_run(self, *args, **kwargs):
843-
if self.cog is not None:
844-
args = (self.cog, *args)
846+
# if self.cog is not None:
847+
# args = (self.cog, *args)
845848
check_func = kwargs.pop('__func', self)
846849
checks = getattr(check_func, '__commands_checks__', getattr(self.func, '__commands_checks__', None))
847850
if not checks:
@@ -850,13 +853,15 @@ async def can_run(self, *args, **kwargs):
850853
return await async_all(check(*args, **kwargs) for check in checks)
851854

852855
async def invoke(self, interaction, *args, **kwargs):
853-
if self.cog is not None:
854-
args = (self.cog, interaction, *args)
855-
else:
856-
args = (interaction, *args)
856+
if not self.func:
857+
return
858+
args = (interaction, *args)
857859
try:
858860
if await self.can_run(*args):
859-
await self.func(*args, **kwargs)
861+
if self.cog:
862+
await self.func(self.cog, *args, **kwargs)
863+
else:
864+
await self.func(*args, **kwargs)
860865
except Exception as exc:
861866
if hasattr(self, 'on_error'):
862867
if self.cog is not None:
@@ -886,10 +891,7 @@ async def invoke_autocomplete(self, interaction, *args, **kwargs):
886891
warnings.warn(f'Sub-Command {self.name} of {self.parent} has options with autocomplete enabled but no autocomplete function.')
887892
return
888893

889-
if self.cog is not None:
890-
args = (self.cog, interaction, *args)
891-
else:
892-
args = (interaction, *args)
894+
args = (interaction, *args)
893895
try:
894896
if await self.can_run(*args, __func=self.autocomplete_func):
895897
await self.autocomplete_func(*args, **kwargs)
@@ -1096,10 +1098,7 @@ async def invoke_autocomplete(self, interaction, *args, **kwargs):
10961098
if self.autocomplete_func is None:
10971099
warnings.warn(f'Application Command {self.name} has options with autocomplete enabled but no autocomplete function.')
10981100
return
1099-
if self.cog is not None:
1100-
args = (self.cog, interaction, *args)
1101-
else:
1102-
args = (interaction, *args)
1101+
args = (interaction, *args)
11031102

11041103
try:
11051104
if await self.can_run(*args, __func=self.autocomplete_func):
@@ -1154,14 +1153,13 @@ def _filter_id_out(argument):
11541153
async def invoke(self, interaction, *args, **kwargs):
11551154
if not self.func:
11561155
return
1157-
if self.cog is not None:
1158-
args = (self.cog, interaction, *args)
1159-
else:
1160-
args = (interaction, *args)
1161-
1156+
args = (interaction, *args)
11621157
try:
11631158
if await self.can_run(*args):
1164-
await self.func(*args, **kwargs)
1159+
if self.cog:
1160+
await self.func(self.cog, *args, **kwargs)
1161+
else:
1162+
await self.func(*args, **kwargs)
11651163
except Exception as exc:
11661164
if hasattr(self, 'on_error'):
11671165
if self.cog is not None:

0 commit comments

Comments
 (0)