Skip to content

Commit bf8b5ed

Browse files
committed
Fixed subcommand raises KeyError at specific condition
1 parent 025ed25 commit bf8b5ed

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

discord_slash/client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def add_slash_command(self,
7272
:param has_subcommands: Whether it has subcommand. Default ``False``.
7373
:type has_subcommands: bool
7474
"""
75+
name = cmd.__name__ if not name else name
76+
name = name.lower()
7577
_cmd = {
7678
"func": cmd,
7779
"description": description,
@@ -80,8 +82,8 @@ def add_slash_command(self,
8082
"api_options": options,
8183
"has_subcommands": has_subcommands
8284
}
83-
self.commands[cmd.__name__ if not name else name] = _cmd
84-
self.logger.debug(f"Added command `{cmd.__name__ if not name else name}`")
85+
self.commands[name] = _cmd
86+
self.logger.debug(f"Added command `{name}`")
8587

8688
def add_subcommand(self,
8789
cmd,
@@ -109,7 +111,10 @@ def add_subcommand(self,
109111
:param guild_ids: List of guild ID of where the command will be used. Default ``None``, which will be global command.
110112
:type guild_ids: List[int]
111113
"""
114+
base = base.lower()
115+
subcommand_group = subcommand_group.lower() if subcommand_group else subcommand_group
112116
name = cmd.__name__ if not name else name
117+
name = name.lower()
113118
_cmd = {
114119
"guild_ids": guild_ids,
115120
"has_subcommands": True
@@ -202,7 +207,7 @@ async def _pick(ctx, choice1, choice2): # Command with 1 or more args.
202207
auto_convert[x["name"]] = x["type"]
203208

204209
def wrapper(cmd):
205-
self.add_slash_command(cmd, name.lower(), description, auto_convert, guild_ids, options)
210+
self.add_slash_command(cmd, name, description, auto_convert, guild_ids, options)
206211
return cmd
207212
return wrapper
208213

@@ -254,7 +259,7 @@ async def _group_kick_user(ctx, user):
254259
"""
255260

256261
def wrapper(cmd):
257-
self.add_subcommand(cmd, base.lower(), subcommand_group.lower(), name.lower(), description, auto_convert, guild_ids)
262+
self.add_subcommand(cmd, base, subcommand_group, name, description, auto_convert, guild_ids)
258263
return cmd
259264
return wrapper
260265

@@ -358,7 +363,7 @@ async def handle_subcommand(self, ctx: model.SlashContext, data: dict):
358363
sub_name = sub["name"]
359364
sub_opts = sub["options"] if "options" in sub else []
360365
for x in sub_opts:
361-
if "options" in x.keys():
366+
if "options" in x.keys() or "value" not in x.keys():
362367
sub_group = x["name"]
363368
selected = base[sub_name][sub_group]
364369
args = await self.process_options(ctx.guild, x["options"], selected["auto_convert"]) \

0 commit comments

Comments
 (0)