Skip to content

Commit bfd3db5

Browse files
committed
refactor: Discard THREAD_UPDATE events referencing an un-cached thread
Signed-off-by: Mathieu Corsham <McCuber04@outlook.de>
1 parent 276dc6e commit bfd3db5

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

discord/state.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -642,21 +642,22 @@ def parse_thread_create(self, data):
642642
self.dispatch('thread_create', thread)
643643

644644
def parse_thread_update(self, data):
645-
guild = self._get_guild(int(data['guild_id']))
646-
thread = guild.get_channel(int(data['id']))
647-
if not thread:
648-
thread = ThreadChannel(state=self, guild=guild, data=data)
649-
if isinstance(thread.parent_channel, ForumChannel):
650-
post = ForumPost(state=self, guild=guild, data=data)
651-
guild._add_post(post)
645+
guild_id = int(data['guild_id'])
646+
guild = self._get_guild(guild_id)
647+
if guild is not None:
648+
thread_id = int(data['id'])
649+
thread = guild.get_channel(thread_id)
650+
if thread is not None:
651+
old_thread = copy.copy(thread)
652+
thread._update(guild, data)
653+
if isinstance(thread.parent_channel, ForumChannel):
654+
self.dispatch('post_update', old_thread, thread)
655+
else:
656+
self.dispatch('thread_update', old_thread, thread)
652657
else:
653-
guild._add_thread(thread)
654-
old_thread = copy.copy(thread)
655-
thread._update(guild, data)
656-
if isinstance(thread.parent_channel, ForumChannel):
657-
self.dispatch('post_update', old_thread, thread)
658+
log.debug('THREAD_UPDATE referencing an unknown channel ID: %s. Discarding.', thread_id)
658659
else:
659-
self.dispatch('thread_update', old_thread, thread)
660+
log.debug('THREAD_UPDATE referencing an unknown guild ID: %s. Discarding.', guild_id)
660661

661662
def parse_thread_delete(self, data):
662663
guild = self._get_guild(int(data['guild_id']))

0 commit comments

Comments
 (0)