cmd.channel.create.thread

Creates a thread from an existing message in a text or announcement channel. Optionally sends an initial message into the thread right after it is created.

This function is available as a sub-method of cmd.channel.create:

JavaScript
const { cmd } = require("syntx.js");

await cmd.channel.create.thread({ channelID, messageID, name, duration, type, returnID, content }, message);

Parameters

ParameterTypeRequiredDescription
channelIDstringYesID of the text or announcement channel where the thread will be started.
messageIDstringYesID of the message to attach the thread to.
namestringYesThe name of the thread.
durationnumberYesAuto-archive duration in minutes. Must be one of: 60, 1440, 4320, 10080.
typestring | ChannelTypeNoThread type. Accepts "public", "private", "announcement", or the equivalent discord.js ChannelType constants. Defaults to ChannelType.PublicThread.
returnIDbooleanNoIf true, returns the created thread's ID instead of the thread object. Defaults to false.
contentstring | objectNoAn initial message to send into the thread. Can be a plain string or a discord.js message options object.
messagediscord.js MessageYesA guild message or interaction, used to access the guild.

Duration values

ValueLabel
601 hour
14401 day
43203 days
100801 week

Returns

discord.js ThreadChannel | string

Returns the created thread object by default. If returnID is true, returns the thread ID as a string instead.

Examples

Create a public thread from a message

JavaScript
client.command({
  name: "startthread",
  content: async (message) => {
    const thread = await cmd.channel.create.thread(
      {
        channelID: message.channel.id,
        messageID: message.id,
        name: "Discussion",
        duration: 1440,
        type: "public",
      },
      message
    );

    message.reply(`Thread created: <#${thread.id}>`);
  },
});

Create a thread with an initial message

JavaScript
client.command({
  name: "threadwithmessage",
  content: async (message) => {
    await cmd.channel.create.thread(
      {
        channelID: message.channel.id,
        messageID: message.id,
        name: "Help request",
        duration: 4320,
        type: "public",
        content: "Welcome to the thread! A staff member will be with you shortly.",
      },
      message
    );
  },
});

Get only the thread ID

JavaScript
client.command({
  name: "threadid",
  content: async (message) => {
    const id = await cmd.channel.create.thread(
      {
        channelID: message.channel.id,
        messageID: message.id,
        name: "Quick thread",
        duration: 60,
        returnID: true,
      },
      message
    );

    message.reply(`New thread ID: ${id}`);
  },
});

Note

Threads can only be created from text or announcement channels. Passing a voice, forum, or category channel ID will throw a SyntxError.

Warning

The bot must have the Create Public Threads or Create Private Threads permission in the target channel, depending on the thread type. If the permission is missing, a SyntxError is thrown.