diff options
| author | Rapptz <[email protected]> | 2021-04-11 22:00:28 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-04-11 22:09:10 -0400 |
| commit | 7bdaa793f68ef5795960bad029357930f4903fc7 (patch) | |
| tree | cf22b248363d943f04959cbb3c9bb13bc04cee75 /discord/state.py | |
| parent | Fix spelling error in utils.__all__ (diff) | |
| download | discord.py-7bdaa793f68ef5795960bad029357930f4903fc7.tar.xz discord.py-7bdaa793f68ef5795960bad029357930f4903fc7.zip | |
Create temporary DMChannels from message create events
This allows for DMChannels to work without falling back to the
Object error case since there is enough information to build a pseudo
DMChannel object.
This is a breaking change since it changes the type of
DMChannel.recipient to Optional[User] for when this faux object is
created.
Diffstat (limited to 'discord/state.py')
| -rw-r--r-- | discord/state.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/discord/state.py b/discord/state.py index 777bed58..d922d210 100644 --- a/discord/state.py +++ b/discord/state.py @@ -338,10 +338,10 @@ class ConnectionState: if len(self._private_channels) > 128: _, to_remove = self._private_channels.popitem(last=False) - if isinstance(to_remove, DMChannel): + if isinstance(to_remove, DMChannel) and to_remove.recipient: self._private_channels_by_user.pop(to_remove.recipient.id, None) - if isinstance(channel, DMChannel): + if isinstance(channel, DMChannel) and channel.recipient: self._private_channels_by_user[channel.recipient.id] = channel def add_dm_channel(self, data): @@ -371,7 +371,7 @@ class ConnectionState: try: guild = self._get_guild(int(data['guild_id'])) except KeyError: - channel = self.get_channel(channel_id) + channel = DMChannel._from_message(self, channel_id, data) guild = None else: channel = guild and guild.get_channel(channel_id) |