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: Single Member Enums Fail Converting To Option #2577

Merged
merged 8 commits into from
Sep 16, 2024
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ These changes are available on the `master` branch, but have not yet been releas
- Added `Member.guild_banner` and `Member.display_banner` properties.
([#2556](https://github.com/Pycord-Development/pycord/pull/2556))

### Fixed

- Fix `Enum` options not setting the correct type when only one choice is available.
([#2577](https://github.com/Pycord-Development/pycord/pull/2577))

### Changed

- Renamed `cover` property of `ScheduledEvent` and `cover` argument of
Expand All @@ -46,8 +51,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2555](https://github.com/Pycord-Development/pycord/pull/2555))
- Fixed missing `stacklevel` parameter in `warn_deprecated` function call inside
`@utils.deprecated`. ([#2500](https://github.com/Pycord-Development/pycord/pull/2500))
- Fixed the type hint in `ConnectionState._polls` to reflect actual behavior, changing it
from `Guild` to `Poll`.
- Fixed the type hint in `ConnectionState._polls` to reflect actual behavior, changing
it from `Guild` to `Poll`.
([#2500](https://github.com/Pycord-Development/pycord/pull/2500))
- Fixed missing `__slots__` attributes in `RawReactionClearEmojiEvent` and
`RawMessagePollVoteEvent`.
Expand Down
8 changes: 6 additions & 2 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def __init__(
enum_choices = []
input_type_is_class = isinstance(input_type, type)
if input_type_is_class and issubclass(input_type, (Enum, DiscordEnum)):
if description is None:
if description is None and input_type.__doc__ is not None:
description = inspect.cleandoc(input_type.__doc__)
if description and len(description) > 100:
description = description[:97] + "..."
Expand All @@ -209,7 +209,11 @@ def __init__(
)
enum_choices = [OptionChoice(e.name, e.value) for e in input_type]
value_class = enum_choices[0].value.__class__
if all(isinstance(elem.value, value_class) for elem in enum_choices):
if enum_choices[
0
].value.__class__ in SlashCommandOptionType.__members__ and all(
Icebluewolf marked this conversation as resolved.
Show resolved Hide resolved
isinstance(elem.value, value_class) for elem in enum_choices
):
input_type = SlashCommandOptionType.from_datatype(
enum_choices[0].value.__class__
)
Expand Down