From 3215cb65e2f9ea0a47a28ba56749b940908710fc Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 29 Mar 2022 22:59:12 -0400 Subject: [PATCH] Raise if custom_id is not a str --- discord/ui/button.py | 3 +++ discord/ui/select.py | 3 +++ discord/ui/text_input.py | 3 +++ 3 files changed, 9 insertions(+) diff --git a/discord/ui/button.py b/discord/ui/button.py index 1f99a2dc8..ed69c0e06 100644 --- a/discord/ui/button.py +++ b/discord/ui/button.py @@ -105,6 +105,9 @@ class Button(Item[V]): if url is None and custom_id is None: custom_id = os.urandom(16).hex() + if custom_id is not None and not isinstance(custom_id, str): + raise TypeError(f'expected custom_id to be str not {custom_id.__class__!r}') + if url is not None: style = ButtonStyle.link diff --git a/discord/ui/select.py b/discord/ui/select.py index a592356b5..d036d4e11 100644 --- a/discord/ui/select.py +++ b/discord/ui/select.py @@ -111,6 +111,9 @@ class Select(Item[V]): self._selected_values: List[str] = [] self._provided_custom_id = custom_id is not MISSING custom_id = os.urandom(16).hex() if custom_id is MISSING else custom_id + if not isinstance(custom_id, str): + raise TypeError(f'expected custom_id to be str not {custom_id.__class__!r}') + options = [] if options is MISSING else options self._underlying = SelectMenu._raw_construct( custom_id=custom_id, diff --git a/discord/ui/text_input.py b/discord/ui/text_input.py index 30c5ff9cc..9d65f34ee 100644 --- a/discord/ui/text_input.py +++ b/discord/ui/text_input.py @@ -104,6 +104,9 @@ class TextInput(Item[V]): self._value: Optional[str] = default self._provided_custom_id = custom_id is not MISSING custom_id = os.urandom(16).hex() if custom_id is MISSING else custom_id + if not isinstance(custom_id, str): + raise TypeError(f'expected custom_id to be str not {custom_id.__class__!r}') + self._underlying = TextInputComponent._raw_construct( type=ComponentType.text_input, label=label,