- (Forum) posts are threads in forum channels.
- Threads can be created per message or per channel.
- Only channel threads can be private.
- For message and forum threads, the thread's ID matches the starter message's ID.
- You can lock threads so only users with the right permissions can send messages.
- Threads can be archived, which removes them from the channel list. This also happens automatically after a period of inactivity.
- You can set how long a thread stays active before auto-archiving with
auto_archive_duration. - Get the archive time with
archive_timestamp.
- You can set how long a thread stays active before auto-archiving with
Events are dispatched for various thread actions:
- on_thread_create: Thread created
- on_thread_delete / on_raw_thread_delete: Thread deleted
- on_thread_update / on_raw_thread_update: Thread updated (locked, renamed, archived, etc)
- on_thread_join: Bot joins a thread
- on_thread_remove: Thread removed (not the same as deleted)
- on_thread_member_join: Member added to thread
- on_thread_member_remove / on_raw_thread_member_remove: Member removed from thread
From a message:
- Use Message.channel to get the thread a message was received from.
From cache:
- Only threads created by the bot are reliably cached. Archived threads and threads your bot can't access are not cached.
- For a thread on a message: Message.thread
- To get a specific thread:
Fetching from API:
- All non-archived threads in a guild: Guild.active_threads()
- All archived threads in a channel: TextChannel.archived_threads()
- Thread created from a message: Message.fetch_thread()
You can create a thread in a text channel, forum channel, or from a specific message in a text channel:
- TextChannel.create_thread(): Can be public or private (defaults to private). Threads from a message are always public.
- ForumChannel.create_thread()
- Message.create_thread()
Threads created from a message or in a forum channel have a starter message. Get the cached message: Thread.starter_message
To fetch the starter message:
starter_message = await thread.parent.fetch_message(thread.id)Or, if you don't need the full object / not waste an API call:
starter_message = thread.get_partial_message(thread.id)
# await starter_message.pin()Some other useful thread attributes:
- Thread.total_message_sent: Total number of messages sent (including deleted).
- Thread.message_count: Approximate number of messages in the thread.
- Thread.member_count: Approximate number of members (max 50).
- Thread.archiver_id: User ID of who archived the thread.
- Thread.parent: Parent channel of the thread.
- Thread.owner: User who created the thread.
Threads can be one of three types, depending on where or how they were created:
- ChannelType.news_thread: Created in an announcement channel
- ChannelType.private_thread
- ChannelType.public_thread
Related: