create_forum_post
Create a new post in a Discord forum channel by specifying server, channel, title, and content. Apply tags and set auto-archive duration for organized discussions.
Instructions
Create a new post in a forum channel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| channelId | Yes | The ID of the forum channel | |
| name | Yes | Title of the post | |
| content | Yes | Content of the initial message | |
| appliedTags | No | Tag IDs to apply | |
| autoArchiveDuration | No | Auto archive minutes | |
| reason | No | Reason for creating |
Implementation Reference
- src/tools/thread-tools.ts:136-176 (handler)The core handler function that executes the create_forum_post tool. It validates the channel is a forum channel, maps autoArchiveDuration, creates the thread with initial message and tags, and returns success/error response.async ({ guildId, channelId, name, content, appliedTags, autoArchiveDuration, 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.GuildForum) { throw new Error('Channel is not a forum channel'); } const forumChannel = channel as ForumChannel; const archiveDurationMap: Record<string, ThreadAutoArchiveDuration> = { '60': ThreadAutoArchiveDuration.OneHour, '1440': ThreadAutoArchiveDuration.OneDay, '4320': ThreadAutoArchiveDuration.ThreeDays, '10080': ThreadAutoArchiveDuration.OneWeek, }; const thread = await forumChannel.threads.create({ name, message: { content }, appliedTags, autoArchiveDuration: autoArchiveDuration ? archiveDurationMap[autoArchiveDuration] : undefined, reason, }); return { id: thread.id, name: thread.name, parentId: thread.parentId, appliedTags: thread.appliedTags, message: 'Forum post 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/tools/thread-tools.ts:127-135 (schema)Zod input schema defining parameters for creating a forum post: guildId, channelId, name (title), content, optional tags, autoArchiveDuration, and reason.{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the forum channel'), name: z.string().describe('Title of the post'), content: z.string().describe('Content of the initial message'), appliedTags: z.array(z.string()).optional().describe('Tag IDs to apply'), autoArchiveDuration: z.enum(['60', '1440', '4320', '10080']).optional().describe('Auto archive minutes'), reason: z.string().optional().describe('Reason for creating'), },
- src/tools/thread-tools.ts:124-177 (registration)Registration of the 'create_forum_post' tool within registerThreadTools function using server.tool(name, description, schema, handler).server.tool( 'create_forum_post', 'Create a new post in a forum channel', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the forum channel'), name: z.string().describe('Title of the post'), content: z.string().describe('Content of the initial message'), appliedTags: z.array(z.string()).optional().describe('Tag IDs to apply'), autoArchiveDuration: z.enum(['60', '1440', '4320', '10080']).optional().describe('Auto archive minutes'), reason: z.string().optional().describe('Reason for creating'), }, async ({ guildId, channelId, name, content, appliedTags, autoArchiveDuration, 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.GuildForum) { throw new Error('Channel is not a forum channel'); } const forumChannel = channel as ForumChannel; const archiveDurationMap: Record<string, ThreadAutoArchiveDuration> = { '60': ThreadAutoArchiveDuration.OneHour, '1440': ThreadAutoArchiveDuration.OneDay, '4320': ThreadAutoArchiveDuration.ThreeDays, '10080': ThreadAutoArchiveDuration.OneWeek, }; const thread = await forumChannel.threads.create({ name, message: { content }, appliedTags, autoArchiveDuration: autoArchiveDuration ? archiveDurationMap[autoArchiveDuration] : undefined, reason, }); return { id: thread.id, name: thread.name, parentId: thread.parentId, appliedTags: thread.appliedTags, message: 'Forum post 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:64-64 (registration)Top-level call to registerThreadTools(server) in createMcpServer(), which includes the create_forum_post tool registration.registerThreadTools(server);
- src/index.ts:21-21 (registration)Import of registerThreadTools from thread-tools.ts in the main index.ts file.import { registerThreadTools } from './tools/thread-tools.js';