diff --git a/discord/channel.py b/discord/channel.py index 52bb4706903b..f60e22c0d91a 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -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']) @@ -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.""" diff --git a/discord/state.py b/discord/state.py index 6012b92120b5..26f443462a31 100644 --- a/discord/state.py +++ b/discord/state.py @@ -1586,7 +1586,8 @@ def parse_typing_start(self, data: gw.TypingStartEvent) -> None: if channel is not None: if isinstance(channel, DMChannel): - channel.recipient = raw.user + if raw.user is not None and raw.user not in channel.recipients: + channel.recipients.append(raw.user) elif guild is not None: raw.user = guild.get_member(raw.user_id)