From 148816c4e8316c2bcad49e81882d8a180734154a Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 23 Sep 2017 18:54:12 -0400 Subject: [PATCH] Temporarily add created channels to cache. This should fix issues when doing a `abc.GuildChannel.edit` immediately afterwards and then when the corresponding CHANNEL_CREATE comes in the channel instance should hopefully be overwritten by the authoritative figure, the WebSocket. --- discord/guild.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 1ab9cea0e..e241531f6 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -601,7 +601,11 @@ class Guild(Hashable): The channel that was just created. """ data = yield from self._create_channel(name, overwrites, ChannelType.text, reason=reason) - return TextChannel(state=self._state, guild=self, data=data) + channel = TextChannel(state=self._state, guild=self, data=data) + + # temporarily add to the cache + self._channels[channel.id] = channel + return channel @asyncio.coroutine def create_voice_channel(self, name, *, overwrites=None, reason=None): @@ -610,7 +614,11 @@ class Guild(Hashable): Same as :meth:`create_text_channel` except makes a :class:`VoiceChannel` instead. """ data = yield from self._create_channel(name, overwrites, ChannelType.voice, reason=reason) - return VoiceChannel(state=self._state, guild=self, data=data) + channel = VoiceChannel(state=self._state, guild=self, data=data) + + # temporarily add to the cache + self._channels[channel.id] = channel + return channel @asyncio.coroutine def create_category(self, name, *, overwrites=None, reason=None): @@ -619,7 +627,11 @@ class Guild(Hashable): Same as :meth:`create_text_channel` except makes a :class:`CategoryChannel` instead. """ data = yield from self._create_channel(name, overwrites, ChannelType.category, reason=reason) - return CategoryChannel(state=self._state, guild=self, data=data) + channel = CategoryChannel(state=self._state, guild=self, data=data) + + # temporarily add to the cache + self._channels[channel.id] = channel + return channel create_category_channel = create_category