Skip to main content
Glama

create_thread

Create a new thread in a Discord server channel to organize discussions around specific topics or messages.

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 guild and channel, validates the channel type, maps autoArchiveDuration, and creates a thread either from a message or a new public/private thread using Discord.js API.
    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 guildId, channelId, name, and optional fields like messageId, autoArchiveDuration, 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'), },
  • The server.tool() call that registers the create_thread tool, providing name, description, input schema, and handler function within the registerThreadTools function.
    server.tool( 'create_thread', '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) }] }; } );
  • src/index.ts:63-63 (registration)
    Call to registerThreadTools(server) which includes the registration of create_thread among other thread tools.
    registerThreadTools(server);

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