Skip to content

Commit 320631c

Browse files
authored
Merge pull request #127 from eunwoo1104/anothercat/args-kwargs
Add kwargs and args attrs to context
2 parents 22fa87d + 1761f22 commit 320631c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

discord_slash/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,15 @@ async def invoke_command(self, func, ctx, args):
691691
try:
692692
not_kwargs = False
693693
if isinstance(args, dict):
694+
ctx.kwargs = args
695+
ctx.args = list(args.values())
694696
try:
695697
await func.invoke(ctx, **args)
696698
except TypeError:
697699
args = list(args.values())
698700
not_kwargs = True
699701
else:
702+
ctx.args = args
700703
not_kwargs = True
701704
if not_kwargs:
702705
await func.invoke(ctx, *args)

discord_slash/context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class SlashContext:
1818
1919
:ivar message: Message that invoked the slash command.
2020
:ivar name: Name of the command.
21+
:ivar args: List of processed arguments invoked with the command.
22+
:ivar kwargs: Dictionary of processed arguments invoked with the command.
2123
:ivar subcommand_name: Subcommand of the command.
2224
:ivar subcommand_group: Subcommand group of the command.
2325
:ivar interaction_id: Interaction ID of the command message.
@@ -42,6 +44,8 @@ def __init__(self,
4244
self.__token = _json["token"]
4345
self.message = None # Should be set later.
4446
self.name = self.command = self.invoked_with = _json["data"]["name"]
47+
self.args = []
48+
self.kwargs = {}
4549
self.subcommand_name = self.invoked_subcommand = self.subcommand_passed = None
4650
self.subcommand_group = self.invoked_subcommand_group = self.subcommand_group_passed = None
4751
self.interaction_id = _json["id"]

0 commit comments

Comments
 (0)