Skip to content

Commit

Permalink
fix: Single Member Enums Fail Converting To Option (Pycord-Developmen…
Browse files Browse the repository at this point in the history
…t#2577)

* fix: Check If Enum Has Docstring Before Using It As Option Description

* fix: Single Item Enums Of Invalid Types Not Converting To String

* chore: Update Changelog

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

* chore: I Used The Wrong PR Number

* Update discord/commands/options.py

Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Signed-off-by: Ice Wolfy <44532864+Icebluewolf@users.noreply.github.com>

---------

Signed-off-by: Ice Wolfy <44532864+Icebluewolf@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 16, 2024
1 parent cd53c9c commit 96180fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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
6 changes: 4 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,9 @@ 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 value_class in SlashCommandOptionType.__members__ and all(
isinstance(elem.value, value_class) for elem in enum_choices
):
input_type = SlashCommandOptionType.from_datatype(
enum_choices[0].value.__class__
)
Expand Down

0 comments on commit 96180fb

Please sign in to comment.