From 7c71c9fce0cee28fc00f70f647ffac5c4dfac6d8 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Thu, 8 Jun 2023 17:09:41 -0700 Subject: [PATCH] fix: values access before interaction (#2104) Signed-off-by: plun1331 <49261529+plun1331@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 ++ discord/ui/select.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd4904d2f..c94cf00022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -129,6 +129,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2079](https://github.com/Pycord-Development/pycord/pull/2079)) - Fixed `HTTPException` when trying to create a forum thread with files. ([#2075](https://github.com/Pycord-Development/pycord/pull/2075)) +- Fixed `AttributeError` when accessing a `Select`'s values when it hasn't been + interacted with. ([#2104](https://github.com/Pycord-Development/pycord/pull/2104)) ## [2.4.1] - 2023-03-20 diff --git a/discord/ui/select.py b/discord/ui/select.py index 5b373bd188..fb55d39d1d 100644 --- a/discord/ui/select.py +++ b/discord/ui/select.py @@ -334,10 +334,13 @@ def values( | list[Member | User | Role] | list[GuildChannel | Thread] ): - """Union[List[:class:`str`], List[Union[:class:`discord.Member`, :class:`discord.User`]], List[:class:`discord.Role`]], - List[Union[:class:`discord.Member`, :class:`discord.User`, :class:`discord.Role`]], List[:class:`discord.abc.GuildChannel`]]: - A list of values that have been selected by the user. + """List[:class:`str`] | List[:class:`discord.Member` | :class:`discord.User`]] | List[:class:`discord.Role`]] | + List[:class:`discord.Member` | :class:`discord.User` | :class:`discord.Role`]] | List[:class:`discord.abc.GuildChannel`] | None: + A list of values that have been selected by the user. This will be ``None`` if the select has not been interacted with yet. """ + if self._interaction is None: + # The select has not been interacted with yet + return None select_type = self._underlying.type if select_type is ComponentType.string_select: return self._selected_values