From 96180fbf9266505e419a0b91fb0c1df581f8a038 Mon Sep 17 00:00:00 2001 From: Ice Wolfy <44532864+Icebluewolf@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:16:16 -0400 Subject: [PATCH] fix: Single Member Enums Fail Converting To Option (#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> --- CHANGELOG.md | 9 +++++++-- discord/commands/options.py | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3314006319..bf46f70f5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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`. diff --git a/discord/commands/options.py b/discord/commands/options.py index 721a03ffe3..382067421f 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -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] + "..." @@ -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__ )