mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 20:28:38 +00:00
Add emoji property to SelectOption
This commit is contained in:
parent
dc8aef7e6a
commit
53694724c1
@ -326,8 +326,6 @@ class SelectOption:
|
|||||||
description: Optional[:class:`str`]
|
description: Optional[:class:`str`]
|
||||||
An additional description of the option, if any.
|
An additional description of the option, if any.
|
||||||
Can only be up to 100 characters.
|
Can only be up to 100 characters.
|
||||||
emoji: Optional[:class:`PartialEmoji`]
|
|
||||||
The emoji of the option, if available.
|
|
||||||
default: :class:`bool`
|
default: :class:`bool`
|
||||||
Whether this option is selected by default.
|
Whether this option is selected by default.
|
||||||
"""
|
"""
|
||||||
@ -336,7 +334,7 @@ class SelectOption:
|
|||||||
'label',
|
'label',
|
||||||
'value',
|
'value',
|
||||||
'description',
|
'description',
|
||||||
'emoji',
|
'_emoji',
|
||||||
'default',
|
'default',
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -353,15 +351,7 @@ class SelectOption:
|
|||||||
self.value: str = label if value is MISSING else value
|
self.value: str = label if value is MISSING else value
|
||||||
self.description: Optional[str] = description
|
self.description: Optional[str] = description
|
||||||
|
|
||||||
if emoji is not None:
|
self.emoji = emoji
|
||||||
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.default: bool = default
|
self.default: bool = default
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
@ -380,6 +370,23 @@ class SelectOption:
|
|||||||
return f'{base}\n{self.description}'
|
return f'{base}\n{self.description}'
|
||||||
return base
|
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
|
@classmethod
|
||||||
def from_dict(cls, data: SelectOptionPayload) -> SelectOption:
|
def from_dict(cls, data: SelectOptionPayload) -> SelectOption:
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user