Add on_raw_thread_update event

This commit is contained in:
Enes Kurbetoğlu 2022-06-03 11:49:32 +03:00 committed by GitHub
parent af265dba06
commit 06c1f44d74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 3 deletions

View File

@ -40,6 +40,7 @@ if TYPE_CHECKING:
MessageReactionRemoveEmojiEvent as ReactionClearEmojiEvent,
MessageUpdateEvent,
IntegrationDeleteEvent,
ThreadUpdateEvent,
ThreadDeleteEvent,
TypingStartEvent,
GuildMemberRemoveEvent,
@ -61,6 +62,7 @@ __all__ = (
'RawReactionClearEvent',
'RawReactionClearEmojiEvent',
'RawIntegrationDeleteEvent',
'RawThreadUpdateEvent',
'RawThreadDeleteEvent',
'RawTypingEvent',
'RawMemberRemoveEvent',
@ -294,6 +296,38 @@ class RawIntegrationDeleteEvent(_RawReprMixin):
self.application_id: Optional[int] = None
class RawThreadUpdateEvent(_RawReprMixin):
"""Represents the payload for a :func:`on_raw_thread_update` event.
.. versionadded:: 2.0
Attributes
----------
thread_id: :class:`int`
The ID of the thread that was updated.
thread_type: :class:`discord.ChannelType`
The channel type of the updated thread.
guild_id: :class:`int`
The ID of the guild the thread is in.
parent_id: :class:`int`
The ID of the channel the thread belongs to.
data: :class:`dict`
The raw data given by the :ddocs:`gateway <topics/gateway#thread-update>`
thread: Optional[:class:`discord.Thread`]
The thread, if it could be found in the internal cache.
"""
__slots__ = ('thread_id', 'thread_type', 'parent_id', 'guild_id', 'data', 'thread')
def __init__(self, data: ThreadUpdateEvent) -> None:
self.thread_id: int = int(data['id'])
self.thread_type: ChannelType = try_enum(ChannelType, data['type'])
self.guild_id: int = int(data['guild_id'])
self.parent_id: int = int(data['parent_id'])
self.data: ThreadUpdateEvent = data
self.thread: Optional[Thread] = None
class RawThreadDeleteEvent(_RawReprMixin):
"""Represents the payload for a :func:`on_raw_thread_delete` event.

View File

@ -874,8 +874,9 @@ class ConnectionState:
_log.debug('THREAD_UPDATE referencing an unknown guild ID: %s. Discarding', guild_id)
return
thread_id = int(data['id'])
thread = guild.get_thread(thread_id)
raw = RawThreadUpdateEvent(data)
raw.thread = thread = guild.get_thread(raw.thread_id)
self.dispatch('raw_thread_update', raw)
if thread is not None:
old = copy.copy(thread)
thread._update(data)

View File

@ -1176,7 +1176,11 @@ Threads
.. function:: on_thread_update(before, after)
Called whenever a thread is updated.
Called whenever a thread is updated. If the thread could
not be found in the internal cache this event will not be called.
Threads will not be in the cache if they are archived.
If you need this information use :func:`on_raw_thread_update` instead.
This requires :attr:`Intents.guilds` to be enabled.
@ -1224,6 +1228,18 @@ Threads
:param thread: The thread that got deleted.
:type thread: :class:`Thread`
.. function:: on_raw_thread_update(payload)
Called whenever a thread is update. Unlike :func:`on_thread_update` this
is called regardless of the thread being in the internal thread cache or not.
This requires :attr:`Intents.guilds` to be enabled.
.. versionadded:: 2.0
:param payload: The raw event payload data.
:type payload: :class:`RawThreadUpdateEvent`
.. function:: on_raw_thread_delete(payload)
Called whenever a thread is deleted. Unlike :func:`on_thread_delete` this
@ -4119,6 +4135,14 @@ RawIntegrationDeleteEvent
.. autoclass:: RawIntegrationDeleteEvent()
:members:
RawThreadUpdateEvent
~~~~~~~~~~~~~~~~~~~~~~
.. attributetable:: RawThreadUpdateEvent
.. autoclass:: RawThreadUpdateEvent()
:members:
RawThreadDeleteEvent
~~~~~~~~~~~~~~~~~~~~~~