Skip to content

Commit

Permalink
on_thread_create event (Pycord-Development#1285)
Browse files Browse the repository at this point in the history
* Ability to diff between new & joined threads

+ docs

* Update discord/state.py

Co-authored-by: krittick <ben@krittick.net>
  • Loading branch information
Middledot and krittick authored Apr 23, 2022
1 parent 0c6cdd6 commit 4279f2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion discord/state.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 4279f2a

Please sign in to comment.