Nostrum.Api.Thread (nostrum v0.11.0-dev)

View Source

Functions for interacting with the Discord API's thread endpoints.

Endpoints related to threads in the Discord Channels API: https://discord.com/developers/docs/resources/channel#start-thread-from-message

Summary

Functions

Add a user to a thread, requires the ability to send messages in the thread.

Create a thread on a channel without an associated message.

Create a new thread in a forum channel.

Join an existing thread, requires that the thread is not archived.

Same as public_archived_threads/2, but only returns private threads that the current user has joined.

Leave a thread, requires that the thread is not archived.

Return all active threads for the current guild.

Returns a thread member object for the specified user if they are a member of the thread

Returns a list of thread members for the specified thread.

Same as public_archived_threads/2, but for private threads instead of public.

Returns a list of archived threads for a given channel.

Removes another user from a thread, requires that the thread is not archived.

Types

thread_with_message_params()

(since 0.10.1)
@type thread_with_message_params() :: %{
  :name => String.t(),
  optional(:auto_archive_duration) => 60 | 1440 | 4320 | 10080,
  optional(:rate_limit_per_user) => 0..21600
}

thread_without_message_params()

(since 0.10.1)
@type thread_without_message_params() :: %{
  :name => String.t(),
  :type => non_neg_integer(),
  optional(:auto_archive_duration) => 60 | 1440 | 4320 | 10080,
  optional(:invitable) => boolean(),
  optional(:rate_limit_per_user) => 0..21600
}

Functions

add_member(thread_id, user_id)

(since 1.x.x)

Add a user to a thread, requires the ability to send messages in the thread.

create(channel_id, options, reason \\ nil)

(since 1.x.x)

Create a thread on a channel without an associated message.

If successful, returns {:ok, Channel}. Otherwise returns a Nostrum.Api.error/0.

An optional reason argument can be given for the audit log.

Options

  • name: Name of the thread, max 100 characters.
  • type: Type of thread, can be either 11 (GUILD_PUBLIC_THREAD) or 12 (GUILD_PRIVATE_THREAD).
  • auto_archive_duration: Duration in minutes to auto-archive the thread after it has been inactive, can be set to 60, 1440, 4320, or 10080.
  • invitable: whether non-moderators can add other non-moderators to a thread; only available when creating a private thread defaults to false.
  • rate_limit_per_user: Rate limit per user in seconds, can be set to any value in 0..21600.

create_in_forum(channel_id, options, reason \\ nil)

(since 1.x.x)

Create a new thread in a forum channel.

If successful, returns {:ok, Channel}. Otherwise returns a Nostrum.Api.error/0.

An optional reason argument can be given for the audit log.

Options

  • name: Name of the thread, max 100 characters.
  • auto_archive_duration: Duration in minutes to auto-archive the thread after it has been inactive, can be set to 60, 1440, 4320, or 10080.
  • rate_limit_per_user: Rate limit per user in seconds, can be set to any value in 0..21600.
  • applied_tags: An array of tag ids to apply to the thread.
  • message: The first message in the created thread.

Thread Message Options

  • content: The content of the message.
  • embeds: A list of embeds.
  • allowed_mentions: Allowed mentions object.
  • components: A list of components.
  • sticker_ids: A list of sticker ids.
  • :files - a list of files where each element is the same format as the :file option. If both :file and :files are specified, :file will be prepended to the :files list.

At least one of content, embeds, sticker_ids, or files must be specified.

create_with_message(channel_id, message_id, options, reason \\ nil)

(since 1.x.x)

Create a thread on a channel message.

The thread_id will be the same as the id of the message, as such no message can have more than one thread.

If successful, returns {:ok, Channel}. Otherwise returns a Nostrum.Api.error/0.

An optional reason argument can be given for the audit log.

Options

  • name: Name of the thread, max 100 characters.
  • auto_archive_duration: Duration in minutes to auto-archive the thread after it has been inactive, can be set to 60, 1440, 4320, or 10080.
  • rate_limit_per_user: Rate limit per user in seconds, can be set to any value in 0..21600.

join(thread_id)

(since 1.x.x)
@spec join(Nostrum.Struct.Channel.id()) :: {:ok} | Nostrum.Api.error()

Join an existing thread, requires that the thread is not archived.

joined_private_archived_threads(channel_id, options \\ [])

(since 1.x.x)
@spec joined_private_archived_threads(
  Nostrum.Struct.Channel.id(),
  Nostrum.Api.options()
) ::
  {:ok,
   %{
     threads: [Nostrum.Struct.Channel.t()],
     members: [Nostrum.Struct.ThreadMember.t()],
     has_more: boolean()
   }}
  | Nostrum.Api.error()

Same as public_archived_threads/2, but only returns private threads that the current user has joined.

leave(thread_id)

(since 1.x.x)
@spec leave(Nostrum.Struct.Channel.id()) :: {:ok} | Nostrum.Api.error()

Leave a thread, requires that the thread is not archived.

list(guild_id)

(since 1.x.x)
@spec list(Nostrum.Struct.Guild.id()) ::
  {:ok,
   %{
     threads: [Nostrum.Struct.Channel.t()],
     members: [Nostrum.Struct.ThreadMember.t()]
   }}
  | Nostrum.Api.error()

Return all active threads for the current guild.

Response body is a map with the following keys:

  • threads: A list of channel objects.
  • members: A list of ThreadMember objects, one for each returned thread the current user has joined.

member(thread_id, user_id)

(since 1.x.x)

Returns a thread member object for the specified user if they are a member of the thread

members(thread_id)

(since 1.x.x)

Returns a list of thread members for the specified thread.

This endpoint is restricted according to whether the GUILD_MEMBERS privileged intent is enabled.

private_archived_threads(channel_id, options \\ [])

(since 1.x.x)
@spec private_archived_threads(Nostrum.Struct.Channel.id(), Nostrum.Api.options()) ::
  {:ok,
   %{
     threads: [Nostrum.Struct.Channel.t()],
     members: [Nostrum.Struct.ThreadMember.t()],
     has_more: boolean()
   }}
  | Nostrum.Api.error()

Same as public_archived_threads/2, but for private threads instead of public.

public_archived_threads(channel_id, options \\ [])

(since 1.x.x)
@spec public_archived_threads(Nostrum.Struct.Channel.id(), Nostrum.Api.options()) ::
  {:ok,
   %{
     threads: [Nostrum.Struct.Channel.t()],
     members: [Nostrum.Struct.ThreadMember.t()],
     has_more: boolean()
   }}
  | Nostrum.Api.error()

Returns a list of archived threads for a given channel.

Threads are sorted by the archive_timestamp field, in descending order.

Response body

Response body is a map with the following keys:

  • threads: A list of channel objects.
  • members: A list of ThreadMember objects, one for each returned thread the current user has joined.
  • has_more: A boolean indicating whether there are more archived threads that can be fetched.

Options

  • before: Returns threads before this timestamp, can be either a DateTime or ISO8601 timestamp.
  • limit: Optional maximum number of threads to return.

remove_member(thread_id, user_id)

(since 1.x.x)
@spec remove_member(Nostrum.Struct.Channel.id(), Nostrum.Struct.User.id()) ::
  {:ok} | Nostrum.Api.error()

Removes another user from a thread, requires that the thread is not archived.

Also requires the MANAGE_THREADS permission, or the creator of the thread if the thread is private.