Skip to content

Commit 3bc95bf

Browse files
committed
Implemented duplicate command warning
1 parent d61cb2b commit 3bc95bf

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

discord_slash/client.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def get_cog_commands(self, cog: commands.Cog):
8282
for x in res:
8383
x.cog = cog
8484
if isinstance(x, model.CogCommandObject):
85+
if x.name in self.commands.keys():
86+
raise error.DuplicateCommand(x.name)
8587
self.commands[x.name] = x
8688
else:
8789
if x.base in self.commands.keys():
@@ -102,8 +104,12 @@ def get_cog_commands(self, cog: commands.Cog):
102104
if x.subcommand_group:
103105
if x.subcommand_group not in self.subcommands:
104106
self.subcommands[x.base][x.subcommand_group] = {}
107+
if x.name in self.subcommands[x.base][x.subcommand_group].keys():
108+
raise error.DuplicateCommand(f"{x.base} {x.subcommand_group} {x.name}")
105109
self.subcommands[x.base][x.subcommand_group][x.name] = x
106110
else:
111+
if x.name in self.subcommands[x.base].keys():
112+
raise error.DuplicateCommand(f"{x.base} {x.name}")
107113
self.subcommands[x.base][x.name] = x
108114

109115
def remove_cog_commands(self, cog):
@@ -290,8 +296,10 @@ def add_slash_command(self,
290296
name = name.lower()
291297
if name in self.commands.keys():
292298
tgt = self.subcommands[name]
293-
has_subcommands = tgt["has_subcommands"]
294-
guild_ids += tgt["guild_ids"]
299+
if not tgt.has_subcommands:
300+
raise error.DuplicateCommand(name)
301+
has_subcommands = tgt.has_subcommands
302+
guild_ids += tgt.allowed_guild_ids
295303
_cmd = {
296304
"func": cmd,
297305
"description": description if description else "No description.",
@@ -370,8 +378,12 @@ def add_subcommand(self,
370378
if subcommand_group:
371379
if subcommand_group not in self.subcommands[base].keys():
372380
self.subcommands[base][subcommand_group] = {}
381+
if name in self.subcommands[base][subcommand_group].keys():
382+
raise error.DuplicateCommand(f"{base} {subcommand_group} {name}")
373383
self.subcommands[base][subcommand_group][name] = model.SubcommandObject(_sub, base, name, subcommand_group)
374384
else:
385+
if name in self.subcommands[base].keys():
386+
raise error.DuplicateCommand(f"{base} {name}")
375387
self.subcommands[base][name] = model.SubcommandObject(_sub, base, name)
376388
self.logger.debug(
377389
f"Added subcommand `{base} {subcommand_group if subcommand_group else ''} {cmd.__name__ if not name else name}`")

0 commit comments

Comments
 (0)