Browse Source

Add emoji property to SelectOption

pull/8079/head
z03h 3 years ago
committed by GitHub
parent
commit
53694724c1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      discord/components.py

31
discord/components.py

@ -326,8 +326,6 @@ class SelectOption:
description: Optional[:class:`str`]
An additional description of the option, if any.
Can only be up to 100 characters.
emoji: Optional[:class:`PartialEmoji`]
The emoji of the option, if available.
default: :class:`bool`
Whether this option is selected by default.
"""
@ -336,7 +334,7 @@ class SelectOption:
'label',
'value',
'description',
'emoji',
'_emoji',
'default',
)
@ -353,15 +351,7 @@ class SelectOption:
self.value: str = label if value is MISSING else value
self.description: Optional[str] = description
if emoji is not None:
if isinstance(emoji, str):
emoji = PartialEmoji.from_str(emoji)
elif isinstance(emoji, _EmojiTag):
emoji = emoji._to_partial()
else:
raise TypeError(f'expected emoji to be str, Emoji, or PartialEmoji not {emoji.__class__}')
self.emoji: Optional[PartialEmoji] = emoji
self.emoji = emoji
self.default: bool = default
def __repr__(self) -> str:
@ -380,6 +370,23 @@ class SelectOption:
return f'{base}\n{self.description}'
return base
@property
def emoji(self) -> Optional[PartialEmoji]:
"""Optional[:class:`.PartialEmoji`]: The emoji of the option, if available."""
return self._emoji
@emoji.setter
def emoji(self, value: Optional[Union[str, Emoji, PartialEmoji]]) -> None:
if value is not None:
if isinstance(value, str):
self._emoji = PartialEmoji.from_str(value)
elif isinstance(value, _EmojiTag):
self._emoji = value._to_partial()
else:
raise TypeError(f'expected str, Emoji, or PartialEmoji, received {value.__class__} instead')
else:
self._emoji = None
@classmethod
def from_dict(cls, data: SelectOptionPayload) -> SelectOption:
try:

Loading…
Cancel
Save