From 169f3a8322d23d9912da2b3b3d1d5fcdbaaebdf9 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 4 Jul 2017 18:33:54 -0400 Subject: [PATCH] Don't unnecessarily re-create private channels. New API change[1] will make it so CHANNEL_CREATE will keep getting sent for private channels, so might as well avoid the overhead of constantly creating the channel if we can avoid it. [1]: https://github.com/hammerandchisel/discord-api-docs/issues/184 --- discord/state.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/discord/state.py b/discord/state.py index 79054beec..fa74a3841 100644 --- a/discord/state.py +++ b/discord/state.py @@ -469,10 +469,13 @@ class ConnectionState: def parse_channel_create(self, data): factory, ch_type = _channel_factory(data['type']) channel = None + if ch_type in (ChannelType.group, ChannelType.private): - channel = factory(me=self.user, data=data, state=self) - self._add_private_channel(channel) - self.dispatch('private_channel_create', channel) + channel_id = int(data['id']) + if self._get_private_channel(channel_id) is None: + channel = factory(me=self.user, data=data, state=self) + self._add_private_channel(channel) + self.dispatch('private_channel_create', channel) else: guild_id = utils._get_as_snowflake(data, 'guild_id') guild = self._get_guild(guild_id)