Browse Source

Button labels can be None

pull/6977/head
Zomatree 4 years ago
committed by GitHub
parent
commit
6cc3e572ba
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      discord/components.py
  2. 3
      discord/types/components.py
  3. 20
      discord/ui/button.py

6
discord/components.py

@ -106,8 +106,8 @@ class Button(Component):
The URL this button sends you to. The URL this button sends you to.
disabled: :class:`bool` disabled: :class:`bool`
Whether the button is disabled or not. Whether the button is disabled or not.
label: :class:`str` label: Optional[:class:`str`]
The label of the button. The label of the button, if any.
emoji: Optional[:class:`PartialEmoji`] emoji: Optional[:class:`PartialEmoji`]
The emoji of the button, if available. The emoji of the button, if available.
""" """
@ -127,7 +127,7 @@ class Button(Component):
self.custom_id: Optional[str] = data.get('custom_id') self.custom_id: Optional[str] = data.get('custom_id')
self.url: Optional[str] = data.get('url') self.url: Optional[str] = data.get('url')
self.disabled: bool = data.get('disabled', False) self.disabled: bool = data.get('disabled', False)
self.label: str = data['label'] self.label: Optional[str] = data.get('label')
self.emoji: Optional[PartialEmoji] self.emoji: Optional[PartialEmoji]
try: try:
self.emoji = PartialEmoji.from_dict(data['emoji']) self.emoji = PartialEmoji.from_dict(data['emoji'])

3
discord/types/components.py

@ -41,12 +41,11 @@ class _ButtonComponentOptional(TypedDict, total=False):
url: str url: str
disabled: bool disabled: bool
emoji: PartialEmoji emoji: PartialEmoji
label: str
class ButtonComponent(_ButtonComponentOptional): class ButtonComponent(_ButtonComponentOptional):
type: Literal[2] type: Literal[2]
style: ButtonStyle style: ButtonStyle
label: str
Component = Union[ComponentContainer, ButtonComponent] Component = Union[ComponentContainer, ButtonComponent]

20
discord/ui/button.py

@ -82,8 +82,8 @@ class Button(Item[V]):
The URL this button sends you to. The URL this button sends you to.
disabled: :class:`bool` disabled: :class:`bool`
Whether the button is disabled or not. Whether the button is disabled or not.
label: :class:`str` label: Optional[:class:`str`]
The label of the button. The label of the button, if any.
emoji: Optional[:class:`PartialEmoji`] emoji: Optional[:class:`PartialEmoji`]
The emoji of the button, if available. The emoji of the button, if available.
""" """
@ -101,7 +101,7 @@ class Button(Item[V]):
self, self,
*, *,
style: ButtonStyle, style: ButtonStyle,
label: str, label: Optional[str] = None,
disabled: bool = False, disabled: bool = False,
custom_id: Optional[str] = None, custom_id: Optional[str] = None,
url: Optional[str] = None, url: Optional[str] = None,
@ -174,13 +174,13 @@ class Button(Item[V]):
self._underlying.disabled = bool(value) self._underlying.disabled = bool(value)
@property @property
def label(self) -> str: def label(self) -> Optional[str]:
""":class:`str`: The label of the button.""" """Optional[:class:`str`]: The label of the button, if available."""
return self._underlying.label return self._underlying.label
@label.setter @label.setter
def label(self, value: str): def label(self, value: Optional[str]):
self._underlying.label = str(value) self._underlying.label = str(value) if value is not None else value
@property @property
def emoji(self) -> Optional[PartialEmoji]: def emoji(self) -> Optional[PartialEmoji]:
@ -221,8 +221,8 @@ class Button(Item[V]):
def button( def button(
label: str,
*, *,
label: Optional[str] = None,
custom_id: Optional[str] = None, custom_id: Optional[str] = None,
disabled: bool = False, disabled: bool = False,
style: ButtonStyle = ButtonStyle.secondary, style: ButtonStyle = ButtonStyle.secondary,
@ -245,8 +245,8 @@ def button(
Parameters Parameters
------------ ------------
label: :class:`str` label: Optional[:class:`str`]
The label of the button. The label of the button, if any.
custom_id: Optional[:class:`str`] custom_id: Optional[:class:`str`]
The ID of the button that gets received during an interaction. The ID of the button that gets received during an interaction.
It is recommended not to set this parameter to prevent conflicts. It is recommended not to set this parameter to prevent conflicts.

Loading…
Cancel
Save