mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-06 10:02:01 +00:00
Add on_raw_thread_update event
This commit is contained in:
parent
af265dba06
commit
06c1f44d74
@ -40,6 +40,7 @@ if TYPE_CHECKING:
|
|||||||
MessageReactionRemoveEmojiEvent as ReactionClearEmojiEvent,
|
MessageReactionRemoveEmojiEvent as ReactionClearEmojiEvent,
|
||||||
MessageUpdateEvent,
|
MessageUpdateEvent,
|
||||||
IntegrationDeleteEvent,
|
IntegrationDeleteEvent,
|
||||||
|
ThreadUpdateEvent,
|
||||||
ThreadDeleteEvent,
|
ThreadDeleteEvent,
|
||||||
TypingStartEvent,
|
TypingStartEvent,
|
||||||
GuildMemberRemoveEvent,
|
GuildMemberRemoveEvent,
|
||||||
@ -61,6 +62,7 @@ __all__ = (
|
|||||||
'RawReactionClearEvent',
|
'RawReactionClearEvent',
|
||||||
'RawReactionClearEmojiEvent',
|
'RawReactionClearEmojiEvent',
|
||||||
'RawIntegrationDeleteEvent',
|
'RawIntegrationDeleteEvent',
|
||||||
|
'RawThreadUpdateEvent',
|
||||||
'RawThreadDeleteEvent',
|
'RawThreadDeleteEvent',
|
||||||
'RawTypingEvent',
|
'RawTypingEvent',
|
||||||
'RawMemberRemoveEvent',
|
'RawMemberRemoveEvent',
|
||||||
@ -294,6 +296,38 @@ class RawIntegrationDeleteEvent(_RawReprMixin):
|
|||||||
self.application_id: Optional[int] = None
|
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):
|
class RawThreadDeleteEvent(_RawReprMixin):
|
||||||
"""Represents the payload for a :func:`on_raw_thread_delete` event.
|
"""Represents the payload for a :func:`on_raw_thread_delete` event.
|
||||||
|
|
||||||
|
@ -874,8 +874,9 @@ class ConnectionState:
|
|||||||
_log.debug('THREAD_UPDATE referencing an unknown guild ID: %s. Discarding', guild_id)
|
_log.debug('THREAD_UPDATE referencing an unknown guild ID: %s. Discarding', guild_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
thread_id = int(data['id'])
|
raw = RawThreadUpdateEvent(data)
|
||||||
thread = guild.get_thread(thread_id)
|
raw.thread = thread = guild.get_thread(raw.thread_id)
|
||||||
|
self.dispatch('raw_thread_update', raw)
|
||||||
if thread is not None:
|
if thread is not None:
|
||||||
old = copy.copy(thread)
|
old = copy.copy(thread)
|
||||||
thread._update(data)
|
thread._update(data)
|
||||||
|
26
docs/api.rst
26
docs/api.rst
@ -1176,7 +1176,11 @@ Threads
|
|||||||
|
|
||||||
.. function:: on_thread_update(before, after)
|
.. 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.
|
This requires :attr:`Intents.guilds` to be enabled.
|
||||||
|
|
||||||
@ -1224,6 +1228,18 @@ Threads
|
|||||||
:param thread: The thread that got deleted.
|
:param thread: The thread that got deleted.
|
||||||
:type thread: :class:`Thread`
|
: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)
|
.. function:: on_raw_thread_delete(payload)
|
||||||
|
|
||||||
Called whenever a thread is deleted. Unlike :func:`on_thread_delete` this
|
Called whenever a thread is deleted. Unlike :func:`on_thread_delete` this
|
||||||
@ -4119,6 +4135,14 @@ RawIntegrationDeleteEvent
|
|||||||
.. autoclass:: RawIntegrationDeleteEvent()
|
.. autoclass:: RawIntegrationDeleteEvent()
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
RawThreadUpdateEvent
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. attributetable:: RawThreadUpdateEvent
|
||||||
|
|
||||||
|
.. autoclass:: RawThreadUpdateEvent()
|
||||||
|
:members:
|
||||||
|
|
||||||
RawThreadDeleteEvent
|
RawThreadDeleteEvent
|
||||||
~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user