mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-07 10:22:59 +00:00
Implement New Select Types
Co-authored-by: Soheab_ <33902984+Soheab@users.noreply.github.com> Co-authored-by: rdrescher909 <51489753+rdrescher909@users.noreply.github.com> Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
This commit is contained in:
@ -25,7 +25,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import ClassVar, List, Literal, Optional, TYPE_CHECKING, Tuple, Union, overload
|
||||
from .enums import try_enum, ComponentType, ButtonStyle, TextStyle
|
||||
from .enums import try_enum, ComponentType, ButtonStyle, TextStyle, ChannelType
|
||||
from .utils import get_slots, MISSING
|
||||
from .partial_emoji import PartialEmoji, _EmojiTag
|
||||
|
||||
@ -234,6 +234,8 @@ class SelectMenu(Component):
|
||||
|
||||
Attributes
|
||||
------------
|
||||
type: :class:`ComponentType`
|
||||
The type of component.
|
||||
custom_id: Optional[:class:`str`]
|
||||
The ID of the select menu that gets received during an interaction.
|
||||
placeholder: Optional[:class:`str`]
|
||||
@ -248,31 +250,32 @@ class SelectMenu(Component):
|
||||
A list of options that can be selected in this menu.
|
||||
disabled: :class:`bool`
|
||||
Whether the select is disabled or not.
|
||||
channel_types: List[:class:`.ChannelType`]
|
||||
A list of channel types that are allowed to be chosen in this select menu.
|
||||
"""
|
||||
|
||||
__slots__: Tuple[str, ...] = (
|
||||
'type',
|
||||
'custom_id',
|
||||
'placeholder',
|
||||
'min_values',
|
||||
'max_values',
|
||||
'options',
|
||||
'disabled',
|
||||
'channel_types',
|
||||
)
|
||||
|
||||
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
|
||||
|
||||
def __init__(self, data: SelectMenuPayload, /) -> None:
|
||||
self.type: ComponentType = try_enum(ComponentType, data['type'])
|
||||
self.custom_id: str = data['custom_id']
|
||||
self.placeholder: Optional[str] = data.get('placeholder')
|
||||
self.min_values: int = data.get('min_values', 1)
|
||||
self.max_values: int = data.get('max_values', 1)
|
||||
self.options: List[SelectOption] = [SelectOption.from_dict(option) for option in data.get('options', [])]
|
||||
self.disabled: bool = data.get('disabled', False)
|
||||
|
||||
@property
|
||||
def type(self) -> Literal[ComponentType.select]:
|
||||
""":class:`ComponentType`: The type of component."""
|
||||
return ComponentType.select
|
||||
self.channel_types: List[ChannelType] = [try_enum(ChannelType, t) for t in data.get('channel_types', [])]
|
||||
|
||||
def to_dict(self) -> SelectMenuPayload:
|
||||
payload: SelectMenuPayload = {
|
||||
@ -280,12 +283,14 @@ class SelectMenu(Component):
|
||||
'custom_id': self.custom_id,
|
||||
'min_values': self.min_values,
|
||||
'max_values': self.max_values,
|
||||
'options': [op.to_dict() for op in self.options],
|
||||
'disabled': self.disabled,
|
||||
}
|
||||
|
||||
if self.placeholder:
|
||||
payload['placeholder'] = self.placeholder
|
||||
if self.options:
|
||||
payload['options'] = [op.to_dict() for op in self.options]
|
||||
if self.channel_types:
|
||||
payload['channel_types'] = [t.value for t in self.channel_types]
|
||||
|
||||
return payload
|
||||
|
||||
|
Reference in New Issue
Block a user