Skip to content

Commit 4e43974

Browse files
authored
fix!: constant command synchronization even without changes on the command (#672)
1 parent 567f32a commit 4e43974

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

interactions/client.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,28 @@ async def __compare_sync(self, data: dict, pool: List[dict]) -> bool:
132132
:return: Whether the command has changed or not.
133133
:rtype: bool
134134
"""
135-
attrs: List[str] = ["type", "name", "description", "options", "guild_id"]
135+
attrs: List[str] = [
136+
name for name in ApplicationCommand.__slots__ if not name.startswith("_")
137+
]
136138
log.info(f"Current attributes to compare: {', '.join(attrs)}.")
137139
clean: bool = True
138140

139141
for command in pool:
140142
if command["name"] == data["name"]:
143+
if not isinstance(command.get("options"), list):
144+
command["options"] = []
145+
# this will ensure that the option will be an emtpy list, since discord returns `None`
146+
# when no options are present, but they're in the data as `[]`
147+
if command.get("guild_id") and not isinstance(command.get("guild_id"), int):
148+
if isinstance(command.get("guild_id"), list):
149+
command["guild_id"] = [int(_) for _ in command["guild_id"]]
150+
else:
151+
command["guild_id"] = int(command["guild_id"])
152+
# ensure that IDs are present as integers since discord returns strings.
141153
for attr in attrs:
142-
if hasattr(data, attr) and command.get(attr) == data.get(attr):
154+
155+
if data.get(attr, None) and command.get(attr) == data.get(attr):
156+
# hasattr checks `dict.attr` not `dict[attr]`
143157
continue
144158
else:
145159
clean = False
@@ -234,7 +248,6 @@ async def _synchronize(self, payload: Optional[dict] = None) -> None:
234248
if isinstance(commands, dict):
235249
if commands.get("code"): # Error exists.
236250
raise JSONException(commands["code"], message=f'{commands["message"]} |')
237-
# TODO: redo error handling.
238251
elif isinstance(commands, list):
239252
for command in commands:
240253
if command.get("code"):

0 commit comments

Comments
 (0)