Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: KeyError when using method 'individual' #1925

Merged
merged 10 commits into from May 13, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -111,6 +111,8 @@ These changes are available on the `master` branch, but have not yet been releas
listeners. ([#2044](https://github.com/Pycord-Development/pycord/pull/2044))
- Fixed unloading of cogs having bridge commands.
([#2048](https://github.com/Pycord-Development/pycord/pull/2048))
- Fixed the Slash command syncronization method `indiviual`.
([#1925](https://github.com/Pycord-Development/pycord/pull/1925))

## [2.4.1] - 2023-03-20

Expand Down
37 changes: 28 additions & 9 deletions discord/bot.py
Expand Up @@ -501,21 +501,24 @@
)

def register(
method: Literal["bulk", "upsert", "delete", "edit"], *args, **kwargs
method: Literal["bulk", "upsert", "delete", "edit"],
*args,
cmd_name: str = None,
guild_id: int | None = None,
**kwargs,
):
if kwargs.pop("_log", True):
if method == "bulk":
_log.debug(
f"Bulk updating commands {[c['name'] for c in args[0]]} for"
f" guild {guild_id}"
)
# TODO: Find where "cmd" is defined
elif method == "upsert":
_log.debug(f"Creating command {cmd['name']} for guild {guild_id}") # type: ignore
_log.debug(f"Creating command {cmd_name} for guild {guild_id}") # type: ignore

Check warning on line 517 in discord/bot.py

View check run for this annotation

Codecov / codecov/patch

discord/bot.py#L517

Added line #L517 was not covered by tests
elif method == "edit":
_log.debug(f"Editing command {cmd['name']} for guild {guild_id}") # type: ignore
_log.debug(f"Editing command {cmd_name} for guild {guild_id}") # type: ignore

Check warning on line 519 in discord/bot.py

View check run for this annotation

Codecov / codecov/patch

discord/bot.py#L519

Added line #L519 was not covered by tests
elif method == "delete":
_log.debug(f"Deleting command {cmd['name']} for guild {guild_id}") # type: ignore
_log.debug(f"Deleting command {cmd_name} for guild {guild_id}") # type: ignore

Check warning on line 521 in discord/bot.py

View check run for this annotation

Codecov / codecov/patch

discord/bot.py#L521

Added line #L521 was not covered by tests
return _register(method, *args, **kwargs)

pending_actions = []
Expand Down Expand Up @@ -602,15 +605,31 @@
registered = []
for cmd in filtered_no_action:
if cmd["action"] == "delete":
await register("delete", cmd["command"])
await register(

Check warning on line 608 in discord/bot.py

View check run for this annotation

Codecov / codecov/patch

discord/bot.py#L608

Added line #L608 was not covered by tests
"delete",
cmd["id"],
cmd_name=cmd["command"].name,
guild_id=guild_id,
)
continue
if cmd["action"] == "edit":
registered.append(
await register("edit", cmd["id"], cmd["command"].to_dict())
await register(
"edit",
cmd["id"],
cmd["command"].to_dict(),
cmd_name=cmd["command"].name,
guild_id=guild_id,
)
)
elif cmd["action"] == "upsert":
registered.append(
await register("upsert", cmd["command"].to_dict())
await register(
"upsert",
cmd["command"].to_dict(),
cmd_name=cmd["command"].name,
guild_id=guild_id,
)
)
else:
raise ValueError(f"Unknown action: {cmd['action']}")
Expand All @@ -628,7 +647,7 @@
)
else:
data = [cmd.to_dict() for cmd in pending]
registered = await register("bulk", data)
registered = await register("bulk", data, guild_id=guild_id)

Check warning on line 650 in discord/bot.py

View check run for this annotation

Codecov / codecov/patch

discord/bot.py#L650

Added line #L650 was not covered by tests

for i in registered:
cmd = get(
Expand Down