Skip to content
This repository was archived by the owner on Aug 28, 2019. It is now read-only.

Commit 06c1f44

Browse files
authored
Add on_raw_thread_update event
1 parent af265db commit 06c1f44

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

discord/raw_models.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
MessageReactionRemoveEmojiEvent as ReactionClearEmojiEvent,
4141
MessageUpdateEvent,
4242
IntegrationDeleteEvent,
43+
ThreadUpdateEvent,
4344
ThreadDeleteEvent,
4445
TypingStartEvent,
4546
GuildMemberRemoveEvent,
@@ -61,6 +62,7 @@
6162
'RawReactionClearEvent',
6263
'RawReactionClearEmojiEvent',
6364
'RawIntegrationDeleteEvent',
65+
'RawThreadUpdateEvent',
6466
'RawThreadDeleteEvent',
6567
'RawTypingEvent',
6668
'RawMemberRemoveEvent',
@@ -294,6 +296,38 @@ def __init__(self, data: IntegrationDeleteEvent) -> None:
294296
self.application_id: Optional[int] = None
295297

296298

299+
class RawThreadUpdateEvent(_RawReprMixin):
300+
"""Represents the payload for a :func:`on_raw_thread_update` event.
301+
302+
.. versionadded:: 2.0
303+
304+
Attributes
305+
----------
306+
thread_id: :class:`int`
307+
The ID of the thread that was updated.
308+
thread_type: :class:`discord.ChannelType`
309+
The channel type of the updated thread.
310+
guild_id: :class:`int`
311+
The ID of the guild the thread is in.
312+
parent_id: :class:`int`
313+
The ID of the channel the thread belongs to.
314+
data: :class:`dict`
315+
The raw data given by the :ddocs:`gateway <topics/gateway#thread-update>`
316+
thread: Optional[:class:`discord.Thread`]
317+
The thread, if it could be found in the internal cache.
318+
"""
319+
320+
__slots__ = ('thread_id', 'thread_type', 'parent_id', 'guild_id', 'data', 'thread')
321+
322+
def __init__(self, data: ThreadUpdateEvent) -> None:
323+
self.thread_id: int = int(data['id'])
324+
self.thread_type: ChannelType = try_enum(ChannelType, data['type'])
325+
self.guild_id: int = int(data['guild_id'])
326+
self.parent_id: int = int(data['parent_id'])
327+
self.data: ThreadUpdateEvent = data
328+
self.thread: Optional[Thread] = None
329+
330+
297331
class RawThreadDeleteEvent(_RawReprMixin):
298332
"""Represents the payload for a :func:`on_raw_thread_delete` event.
299333

discord/state.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,9 @@ def parse_thread_update(self, data: gw.ThreadUpdateEvent) -> None:
874874
_log.debug('THREAD_UPDATE referencing an unknown guild ID: %s. Discarding', guild_id)
875875
return
876876

877-
thread_id = int(data['id'])
878-
thread = guild.get_thread(thread_id)
877+
raw = RawThreadUpdateEvent(data)
878+
raw.thread = thread = guild.get_thread(raw.thread_id)
879+
self.dispatch('raw_thread_update', raw)
879880
if thread is not None:
880881
old = copy.copy(thread)
881882
thread._update(data)

docs/api.rst

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,11 @@ Threads
11761176

11771177
.. function:: on_thread_update(before, after)
11781178

1179-
Called whenever a thread is updated.
1179+
Called whenever a thread is updated. If the thread could
1180+
not be found in the internal cache this event will not be called.
1181+
Threads will not be in the cache if they are archived.
1182+
1183+
If you need this information use :func:`on_raw_thread_update` instead.
11801184

11811185
This requires :attr:`Intents.guilds` to be enabled.
11821186

@@ -1224,6 +1228,18 @@ Threads
12241228
:param thread: The thread that got deleted.
12251229
:type thread: :class:`Thread`
12261230

1231+
.. function:: on_raw_thread_update(payload)
1232+
1233+
Called whenever a thread is update. Unlike :func:`on_thread_update` this
1234+
is called regardless of the thread being in the internal thread cache or not.
1235+
1236+
This requires :attr:`Intents.guilds` to be enabled.
1237+
1238+
.. versionadded:: 2.0
1239+
1240+
:param payload: The raw event payload data.
1241+
:type payload: :class:`RawThreadUpdateEvent`
1242+
12271243
.. function:: on_raw_thread_delete(payload)
12281244

12291245
Called whenever a thread is deleted. Unlike :func:`on_thread_delete` this
@@ -4119,6 +4135,14 @@ RawIntegrationDeleteEvent
41194135
.. autoclass:: RawIntegrationDeleteEvent()
41204136
:members:
41214137

4138+
RawThreadUpdateEvent
4139+
~~~~~~~~~~~~~~~~~~~~~~
4140+
4141+
.. attributetable:: RawThreadUpdateEvent
4142+
4143+
.. autoclass:: RawThreadUpdateEvent()
4144+
:members:
4145+
41224146
RawThreadDeleteEvent
41234147
~~~~~~~~~~~~~~~~~~~~~~
41244148

0 commit comments

Comments
 (0)