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
| Parameter | Type | Required | Description |
|---|---|---|---|
channelID | string | Yes | ID of the text or announcement channel where the thread will be started. |
messageID | string | Yes | ID of the message to attach the thread to. |
name | string | Yes | The name of the thread. |
duration | number | Yes | Auto-archive duration in minutes. Must be one of: 60, 1440, 4320, 10080. |
type | string | ChannelType | No | Thread type. Accepts "public", "private", "announcement", or the equivalent discord.js ChannelType constants. Defaults to ChannelType.PublicThread. |
returnID | boolean | No | If true, returns the created thread's ID instead of the thread object. Defaults to false. |
content | string | object | No | An initial message to send into the thread. Can be a plain string or a discord.js message options object. |
message | discord.js Message | Yes | A guild message or interaction, used to access the guild. |
Duration values
| Value | Label |
|---|---|
60 | 1 hour |
1440 | 1 day |
4320 | 3 days |
10080 | 1 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.