Skip to content

Commit

Permalink
fix: slash options broken when declared explicitly (Pycord-Developmen…
Browse files Browse the repository at this point in the history
…t#2332)

* Update core.py

* Update CHANGELOG.md

* style(pre-commit): auto fixes from pre-commit.com hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
plun1331 and pre-commit-ci[bot] authored Jan 28, 2024
1 parent 60097c5 commit f0c33dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ These changes are available on the `master` branch, but have not yet been releas
([#2299](https://github.com/Pycord-Development/pycord/issues/2299))
- Fixed `AttributeError` when copying groups on startup.
([#2331](https://github.com/Pycord-Development/pycord/issues/2331))
- Fixed application command options causing errors if declared through the option
decorator or kwarg.
([#2332](https://github.com/Pycord-Development/pycord/issues/2332))

## [2.4.1] - 2023-03-20

Expand Down
11 changes: 7 additions & 4 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:

self.attached_to_group: bool = False

self.options: list[Option] = kwargs.get("options", [])
self._options_kwargs = kwargs.get("options", [])
self.options: list[Option] = []
self._validate_parameters()

try:
Expand All @@ -704,7 +705,7 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:

def _validate_parameters(self):
params = self._get_signature_parameters()
if kwop := self.options:
if kwop := self._options_kwargs:
self.options = self._match_option_param_names(params, kwop)
else:
self.options = self._parse_options(params)
Expand All @@ -727,6 +728,8 @@ def _check_required_params(self, params):
def _parse_options(self, params, *, check_params: bool = True) -> list[Option]:
if check_params:
params = self._check_required_params(params)
else:
params = iter(params.items())

final_options = []
for p_name, p_obj in params:
Expand Down Expand Up @@ -790,6 +793,7 @@ def _parse_options(self, params, *, check_params: bool = True) -> list[Option]:
return final_options

def _match_option_param_names(self, params, options):
options = list(options)
params = self._check_required_params(params)

check_annotations: list[Callable[[Option, type], bool]] = [
Expand Down Expand Up @@ -855,8 +859,7 @@ def cog(self, value):
or value is None
and old_cog is not None
):
params = self._get_signature_parameters()
self.options = self._parse_options(params)
self._validate_parameters()

@property
def is_subcommand(self) -> bool:
Expand Down

0 comments on commit f0c33dd

Please sign in to comment.