Skip to main content
Glama

create_thread

Create a new thread in a Discord server channel to organize discussions or focus on specific topics.

Instructions

Create a new thread

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the parent channel
nameYesName of the thread
messageIdNoMessage ID to start thread from
autoArchiveDurationNoAuto archive after minutes
typeNoThread type (default public)
reasonNoReason for creating

Implementation Reference

  • The handler function that implements the create_thread tool logic. It fetches the Discord guild and channel, validates the channel type, maps auto-archive durations, and creates either a public/private thread or starts one from a message using Discord.js APIs. Returns JSON response or error.
    async ({ guildId, channelId, name, messageId, autoArchiveDuration, type = 'public', reason }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!channel || channel.type !== ChannelType.GuildText) { throw new Error('Channel does not support creating threads'); } const textChannel = channel as TextChannel; const archiveDurationMap: Record<string, ThreadAutoArchiveDuration> = { '60': ThreadAutoArchiveDuration.OneHour, '1440': ThreadAutoArchiveDuration.OneDay, '4320': ThreadAutoArchiveDuration.ThreeDays, '10080': ThreadAutoArchiveDuration.OneWeek, }; let thread; if (messageId) { const message = await textChannel.messages.fetch(messageId); thread = await message.startThread({ name, autoArchiveDuration: autoArchiveDuration ? archiveDurationMap[autoArchiveDuration] : undefined, reason, }); } else { thread = await textChannel.threads.create({ name, autoArchiveDuration: autoArchiveDuration ? archiveDurationMap[autoArchiveDuration] : undefined, type: type === 'private' ? ChannelType.PrivateThread : ChannelType.PublicThread, reason, }); } return { id: thread.id, name: thread.name, type: ChannelType[thread.type], parentId: thread.parentId, message: 'Thread created successfully', }; }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; }
  • Zod schema defining the input parameters for the create_thread tool, including guild ID, channel ID, thread name, optional message ID, auto-archive duration, type, and reason.
    guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the parent channel'), name: z.string().describe('Name of the thread'), messageId: z.string().optional().describe('Message ID to start thread from'), autoArchiveDuration: z.enum(['60', '1440', '4320', '10080']).optional().describe('Auto archive after minutes'), type: z.enum(['public', 'private']).optional().describe('Thread type (default public)'), reason: z.string().optional().describe('Reason for creating'), },
  • Registration of the create_thread tool via server.tool() within the registerThreadTools function, specifying name, description, input schema, and handler.
    'Create a new thread', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the parent channel'), name: z.string().describe('Name of the thread'), messageId: z.string().optional().describe('Message ID to start thread from'), autoArchiveDuration: z.enum(['60', '1440', '4320', '10080']).optional().describe('Auto archive after minutes'), type: z.enum(['public', 'private']).optional().describe('Thread type (default public)'), reason: z.string().optional().describe('Reason for creating'), }, async ({ guildId, channelId, name, messageId, autoArchiveDuration, type = 'public', reason }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!channel || channel.type !== ChannelType.GuildText) { throw new Error('Channel does not support creating threads'); } const textChannel = channel as TextChannel; const archiveDurationMap: Record<string, ThreadAutoArchiveDuration> = { '60': ThreadAutoArchiveDuration.OneHour, '1440': ThreadAutoArchiveDuration.OneDay, '4320': ThreadAutoArchiveDuration.ThreeDays, '10080': ThreadAutoArchiveDuration.OneWeek, }; let thread; if (messageId) { const message = await textChannel.messages.fetch(messageId); thread = await message.startThread({ name, autoArchiveDuration: autoArchiveDuration ? archiveDurationMap[autoArchiveDuration] : undefined, reason, }); } else { thread = await textChannel.threads.create({ name, autoArchiveDuration: autoArchiveDuration ? archiveDurationMap[autoArchiveDuration] : undefined, type: type === 'private' ? ChannelType.PrivateThread : ChannelType.PublicThread, reason, }); } return { id: thread.id, name: thread.name, type: ChannelType[thread.type], parentId: thread.parentId, message: 'Thread created successfully', }; }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/scarecr0w12/discord-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server