aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZomatree <[email protected]>2021-05-28 03:33:13 +0100
committerGitHub <[email protected]>2021-05-27 22:33:13 -0400
commit6cc3e572ba1b9400b43e4f5abd6b70ef7224c127 (patch)
treeaf6804279d8d3c9692276b265e631f7f594ea748
parentAdd Member.get_role (diff)
downloaddiscord.py-6cc3e572ba1b9400b43e4f5abd6b70ef7224c127.tar.xz
discord.py-6cc3e572ba1b9400b43e4f5abd6b70ef7224c127.zip
Button labels can be None
-rw-r--r--discord/components.py6
-rw-r--r--discord/types/components.py3
-rw-r--r--discord/ui/button.py20
3 files changed, 14 insertions, 15 deletions
diff --git a/discord/components.py b/discord/components.py
index 853ea1ed..924c2152 100644
--- a/discord/components.py
+++ b/discord/components.py
@@ -106,8 +106,8 @@ class Button(Component):
The URL this button sends you to.
disabled: :class:`bool`
Whether the button is disabled or not.
- label: :class:`str`
- The label of the button.
+ label: Optional[:class:`str`]
+ The label of the button, if any.
emoji: Optional[:class:`PartialEmoji`]
The emoji of the button, if available.
"""
@@ -127,7 +127,7 @@ class Button(Component):
self.custom_id: Optional[str] = data.get('custom_id')
self.url: Optional[str] = data.get('url')
self.disabled: bool = data.get('disabled', False)
- self.label: str = data['label']
+ self.label: Optional[str] = data.get('label')
self.emoji: Optional[PartialEmoji]
try:
self.emoji = PartialEmoji.from_dict(data['emoji'])
diff --git a/discord/types/components.py b/discord/types/components.py
index d652c711..2f14f903 100644
--- a/discord/types/components.py
+++ b/discord/types/components.py
@@ -41,12 +41,11 @@ class _ButtonComponentOptional(TypedDict, total=False):
url: str
disabled: bool
emoji: PartialEmoji
-
+ label: str
class ButtonComponent(_ButtonComponentOptional):
type: Literal[2]
style: ButtonStyle
- label: str
Component = Union[ComponentContainer, ButtonComponent]
diff --git a/discord/ui/button.py b/discord/ui/button.py
index 8d208257..72956562 100644
--- a/discord/ui/button.py
+++ b/discord/ui/button.py
@@ -82,8 +82,8 @@ class Button(Item[V]):
The URL this button sends you to.
disabled: :class:`bool`
Whether the button is disabled or not.
- label: :class:`str`
- The label of the button.
+ label: Optional[:class:`str`]
+ The label of the button, if any.
emoji: Optional[:class:`PartialEmoji`]
The emoji of the button, if available.
"""
@@ -101,7 +101,7 @@ class Button(Item[V]):
self,
*,
style: ButtonStyle,
- label: str,
+ label: Optional[str] = None,
disabled: bool = False,
custom_id: Optional[str] = None,
url: Optional[str] = None,
@@ -174,13 +174,13 @@ class Button(Item[V]):
self._underlying.disabled = bool(value)
@property
- def label(self) -> str:
- """:class:`str`: The label of the button."""
+ def label(self) -> Optional[str]:
+ """Optional[:class:`str`]: The label of the button, if available."""
return self._underlying.label
@label.setter
- def label(self, value: str):
- self._underlying.label = str(value)
+ def label(self, value: Optional[str]):
+ self._underlying.label = str(value) if value is not None else value
@property
def emoji(self) -> Optional[PartialEmoji]:
@@ -221,8 +221,8 @@ class Button(Item[V]):
def button(
- label: str,
*,
+ label: Optional[str] = None,
custom_id: Optional[str] = None,
disabled: bool = False,
style: ButtonStyle = ButtonStyle.secondary,
@@ -245,8 +245,8 @@ def button(
Parameters
------------
- label: :class:`str`
- The label of the button.
+ label: Optional[:class:`str`]
+ The label of the button, if any.
custom_id: Optional[:class:`str`]
The ID of the button that gets received during an interaction.
It is recommended not to set this parameter to prevent conflicts.