Skip to content

Commit

Permalink
Add from_channel/role/user classmethods to SelectDefaultValue
Browse files Browse the repository at this point in the history
For easy construction
  • Loading branch information
Soheab committed Sep 25, 2023
1 parent 68852aa commit 86a1124
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion discord/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
SelectDefaultValues as SelectDefaultValuesPayload,
)
from .emoji import Emoji
from .abc import Snowflake

ActionRowChildComponentType = Union['Button', 'SelectMenu', 'TextInput']

Expand Down Expand Up @@ -570,7 +571,28 @@ def to_dict(self) -> SelectDefaultValuesPayload:
'id': self.id,
'type': self._type.value,
}


@classmethod
def from_channel(cls, channel: Snowflake, /) -> Self:
return cls(
id=channel.id,
type=SelectDefaultValueType.channel,
)

@classmethod
def from_role(cls, role: Snowflake, /) -> Self:
return cls(
id=role.id,
type=SelectDefaultValueType.role,
)

@classmethod
def from_user(cls, user: Snowflake, /) -> Self:
return cls(
id=user.id,
type=SelectDefaultValueType.user,
)


@overload
def _component_factory(data: ActionRowChildComponentPayload) -> Optional[ActionRowChildComponentType]:
Expand Down

0 comments on commit 86a1124

Please sign in to comment.