Skip to content

Commit d5dfe8e

Browse files
authored
fix: correctly serialize slash cmd with same names from different scope (#1733)
1 parent 7c9de39 commit d5dfe8e

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

interactions/models/internal/application_commands.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from collections import defaultdict
23
import inspect
34
import re
45
import typing
@@ -1468,9 +1469,9 @@ def application_commands_to_dict( # noqa: C901
14681469
`Client.interactions` should be the variable passed to this
14691470
14701471
"""
1471-
cmd_bases = {} # {cmd_base: [commands]}
1472+
cmd_bases: defaultdict[str, list[InteractionCommand]] = defaultdict(list) # {cmd_base: [commands]}
14721473
"""A store of commands organised by their base command"""
1473-
output = {}
1474+
output: defaultdict["Snowflake_Type", list[dict]] = defaultdict(list)
14741475
"""The output dictionary"""
14751476

14761477
def squash_subcommand(subcommands: List) -> Dict:
@@ -1516,9 +1517,6 @@ def squash_subcommand(subcommands: List) -> Dict:
15161517
for _scope, cmds in commands.items():
15171518
for cmd in cmds.values():
15181519
cmd_name = str(cmd.name)
1519-
if cmd_name not in cmd_bases:
1520-
cmd_bases[cmd_name] = [cmd]
1521-
continue
15221520
if cmd not in cmd_bases[cmd_name]:
15231521
cmd_bases[cmd_name].append(cmd)
15241522

@@ -1558,15 +1556,14 @@ def squash_subcommand(subcommands: List) -> Dict:
15581556
cmd.nsfw = nsfw
15591557
# end validation of attributes
15601558
cmd_data = squash_subcommand(cmd_list)
1559+
1560+
for s in scopes:
1561+
output[s].append(cmd_data)
15611562
else:
1562-
scopes = cmd_list[0].scopes
1563-
cmd_data = cmd_list[0].to_dict()
1564-
for s in scopes:
1565-
if s not in output:
1566-
output[s] = [cmd_data]
1567-
continue
1568-
output[s].append(cmd_data)
1569-
return output
1563+
for cmd in cmd_list:
1564+
for s in cmd.scopes:
1565+
output[s].append(cmd.to_dict())
1566+
return dict(output)
15701567

15711568

15721569
def _compare_commands(local_cmd: dict, remote_cmd: dict) -> bool:

0 commit comments

Comments
 (0)