Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions interactions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,28 @@ async def __compare_sync(self, data: dict, pool: List[dict]) -> bool:
:return: Whether the command has changed or not.
:rtype: bool
"""
attrs: List[str] = ["type", "name", "description", "options", "guild_id"]
attrs: List[str] = [
name for name in ApplicationCommand.__slots__ if not name.startswith("_")
]
log.info(f"Current attributes to compare: {', '.join(attrs)}.")
clean: bool = True

for command in pool:
if command["name"] == data["name"]:
if not isinstance(command.get("options"), list):
command["options"] = []
# this will ensure that the option will be an emtpy list, since discord returns `None`
# when no options are present, but they're in the data as `[]`
if command.get("guild_id") and not isinstance(command.get("guild_id"), int):
if isinstance(command.get("guild_id"), list):
command["guild_id"] = [int(_) for _ in command["guild_id"]]
else:
command["guild_id"] = int(command["guild_id"])
# ensure that IDs are present as integers since discord returns strings.
for attr in attrs:
if hasattr(data, attr) and command.get(attr) == data.get(attr):

if data.get(attr, None) and command.get(attr) == data.get(attr):
# hasattr checks `dict.attr` not `dict[attr]`
continue
else:
clean = False
Expand Down Expand Up @@ -234,7 +248,6 @@ async def _synchronize(self, payload: Optional[dict] = None) -> None:
if isinstance(commands, dict):
if commands.get("code"): # Error exists.
raise JSONException(commands["code"], message=f'{commands["message"]} |')
# TODO: redo error handling.
elif isinstance(commands, list):
for command in commands:
if command.get("code"):
Expand Down