Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_thread_create event #1285

Merged
merged 2 commits into from Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion discord/state.py
Expand Up @@ -897,7 +897,10 @@ def parse_thread_create(self, data) -> None:
has_thread = guild.get_thread(thread.id)
guild._add_thread(thread)
if not has_thread:
self.dispatch("thread_join", thread)
if data.get("newly_created"):
self.dispatch("thread_create", thread)
else:
self.dispatch("thread_join", thread)

def parse_thread_update(self, data) -> None:
guild_id = int(data["guild_id"])
Expand Down
16 changes: 14 additions & 2 deletions docs/api.rst
Expand Up @@ -899,8 +899,7 @@ to handle it, which defaults to print a traceback and ignoring the exception.

.. function:: on_thread_join(thread)

Called whenever a thread is joined or created. Note that from the API's perspective there is no way to
differentiate between a thread being created or the bot joining a thread.
Called whenever a thread is joined.

Note that you can get the guild from :attr:`Thread.guild`.

Expand All @@ -911,6 +910,19 @@ to handle it, which defaults to print a traceback and ignoring the exception.
:param thread: The thread that got joined.
:type thread: :class:`Thread`

.. function:: on_thread_create(thread)

Called whenever a thread is created.

Note that you can get the guild from :attr:`Thread.guild`.

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

.. versionadded:: 2.0

:param thread: The thread that got created.
:type thread: :class:`Thread`

.. function:: on_thread_remove(thread)

Called whenever a thread is removed. This is different from a thread being deleted.
Expand Down