Add raw thread delete event #46

Open
paris-ci wants to merge 3 commits from paris-ci/pr7268 into 2.0
3 changed files with 61 additions and 3 deletions

View File

@ -39,8 +39,11 @@ if TYPE_CHECKING:
from .message import Message
from .partial_emoji import PartialEmoji
from .member import Member
from .threads import Thread
from .enums import ChannelType, try_enum
__all__ = (
'RawMessageDeleteEvent',
'RawBulkMessageDeleteEvent',
@ -49,6 +52,7 @@ __all__ = (
'RawReactionClearEvent',
'RawReactionClearEmojiEvent',
'RawIntegrationDeleteEvent',
'RawThreadDeleteEvent',
)
@ -276,3 +280,31 @@ class RawIntegrationDeleteEvent(_RawReprMixin):
self.application_id: Optional[int] = int(data['application_id'])
except KeyError:
self.application_id: Optional[int] = None
class RawThreadDeleteEvent(_RawReprMixin):
"""Represents the payload for a :func:`on_raw_thread_delete` event.
.. versionadded:: 2.0
Attributes
----------
thread_id: :class:`int`
The ID of the thread that was deleted.
thread_type: :class:`discord.ChannelType`
The channel type of the deleted thread.
guild_id: :class:`int`
The ID of the guild the thread was deleted in.
parent_id: :class:`int`
The ID of the channel the thread was belonged to.
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', 'thread')
def __init__(self, data) -> 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.thread: Optional[Thread] = None

View File

@ -851,8 +851,10 @@ class ConnectionState:
_log.debug('THREAD_DELETE referencing an unknown guild ID: %s. Discarding', guild_id)
return
thread_id = int(data['id'])
thread = guild.get_thread(thread_id)
raw = RawThreadDeleteEvent(data)
raw.thread = thread = guild.get_thread(raw.thread_id)
self.dispatch('raw_thread_delete', raw)
if thread is not None:
guild._remove_thread(thread) # type: ignore
self.dispatch('thread_delete', thread)

View File

@ -718,7 +718,11 @@ to handle it, which defaults to print a traceback and ignoring the exception.
.. function:: on_thread_delete(thread)
Called whenever a thread is deleted.
Called whenever a thread is deleted. 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_delete` instead.
Note that you can get the guild from :attr:`Thread.guild`.
@ -729,6 +733,18 @@ to handle it, which defaults to print a traceback and ignoring the exception.
:param thread: The thread that got deleted.
:type thread: :class:`Thread`
.. function:: on_raw_thread_delete(payload)
Called whenever a thread is deleted. Unlike :func:`on_thread_delete` 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:`RawThreadDeleteEvent`
.. function:: on_thread_member_join(member)
on_thread_member_remove(member)
@ -3902,6 +3918,14 @@ RawIntegrationDeleteEvent
.. autoclass:: RawIntegrationDeleteEvent()
:members:
RawThreadDeleteEvent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. attributetable:: RawThreadDeleteEvent
.. autoclass:: RawThreadDeleteEvent()
:members:
PartialWebhookGuild
~~~~~~~~~~~~~~~~~~~~