Skip to content

Commit

Permalink
Add DMChannel.recipients field
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Mar 22, 2024
1 parent 1ea82cc commit fe165b3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions discord/channel.py
Expand Up @@ -2916,22 +2916,21 @@ class DMChannel(discord.abc.Messageable, discord.abc.PrivateChannel, Hashable):
The user you are participating with in the direct message channel.
If this channel is received through the gateway, the recipient information
may not be always available.
recipients: List[:class:`User`]
The users you are participating with in the DM channel.
.. versionadded:: 2.4
me: :class:`ClientUser`
The user presenting yourself.
id: :class:`int`
The direct message channel ID.
"""

__slots__ = ('id', 'recipient', 'me', '_state')
__slots__ = ('id', 'recipients', 'me', '_state')

def __init__(self, *, me: ClientUser, state: ConnectionState, data: DMChannelPayload):
self._state: ConnectionState = state
self.recipient: Optional[User] = None

recipients = data.get('recipients')
if recipients is not None:
self.recipient = state.store_user(recipients[0])

self.recipients: List[User] = [state.store_user(u) for u in data.get('recipients', [])]
self.me: ClientUser = me
self.id: int = int(data['id'])

Expand All @@ -2951,11 +2950,17 @@ def _from_message(cls, state: ConnectionState, channel_id: int) -> Self:
self = cls.__new__(cls)
self._state = state
self.id = channel_id
self.recipient = None
self.recipients = []
# state.user won't be None here
self.me = state.user # type: ignore
return self

@property
def recipient(self) -> Optional[User]:
if self.recipients:
return self.recipients[0]
return None

@property
def type(self) -> Literal[ChannelType.private]:
""":class:`ChannelType`: The channel's Discord type."""
Expand Down

0 comments on commit fe165b3

Please sign in to comment.