Skip to content

Commit

Permalink
fix: setting options using default syntax makes option optional (#2333)
Browse files Browse the repository at this point in the history
* fix: setting options using default syntax makes option optional

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

* Update CHANGELOG.md

* chore: remove very useful debug statement

---------

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] committed Jan 28, 2024
1 parent f0c33dd commit 5d2ec72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ These changes are available on the `master` branch, but have not yet been releas
- Fixed application command options causing errors if declared through the option
decorator or kwarg.
([#2332](https://github.com/Pycord-Development/pycord/issues/2332))
- Fixed options declared using the 'default' syntax always being optional.
([#2333](https://github.com/Pycord-Development/pycord/issues/2333))

## [2.4.1] - 2023-03-20

Expand Down
16 changes: 7 additions & 9 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,23 +760,21 @@ def _parse_options(self, params, *, check_params: bool = True) -> list[Option]:

if not isinstance(option, Option):
if isinstance(p_obj.default, Option):
p_obj.default.input_type = SlashCommandOptionType.from_datatype(
option
)
if p_obj.default.input_type is None:
p_obj.default.input_type = SlashCommandOptionType.from_datatype(
option
)
option = p_obj.default
else:
option = Option(option)

if option.default is None and not p_obj.default == inspect.Parameter.empty:
if isinstance(p_obj.default, type) and issubclass(
if isinstance(p_obj.default, Option):
pass
elif isinstance(p_obj.default, type) and issubclass(
p_obj.default, (DiscordEnum, Enum)
):
option = Option(p_obj.default)
elif (
isinstance(p_obj.default, Option)
and not (default := p_obj.default.default) is None
):
option.default = default
else:
option.default = p_obj.default
option.required = False
Expand Down

0 comments on commit 5d2ec72

Please sign in to comment.