Skip to content

Commit c0ec0ac

Browse files
committed
Update model.py
forgot to commit this
1 parent 1629ff9 commit c0ec0ac

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

discord_slash/model.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,31 @@ async def invoke(self, *args, **kwargs):
261261
:param args: Args for the command.
262262
:raises: .error.CheckFailure
263263
"""
264-
can_run = await self.can_run(args[0])
264+
args = list(args)
265+
ctx = args.pop(0)
266+
can_run = await self.can_run(ctx)
265267
if not can_run:
266268
raise error.CheckFailure
267269

268-
return await self.func(self.cog, *args, **kwargs)
270+
coro = None # Get rid of annoying IDE complainings.
271+
272+
not_kwargs = False
273+
if args and isinstance(args[0], dict):
274+
kwargs = args[0]
275+
ctx.kwargs = kwargs
276+
ctx.args = list(kwargs.values())
277+
try:
278+
coro = self.func(self.cog, ctx, **kwargs)
279+
except TypeError:
280+
args = list(kwargs.values())
281+
not_kwargs = True
282+
else:
283+
ctx.args = args
284+
not_kwargs = True
285+
if not_kwargs:
286+
coro = self.func(self.cog, ctx, *args)
287+
288+
return await coro
269289

270290

271291
class CogSubcommandObject(SubcommandObject):

0 commit comments

Comments
 (0)