create_channel
Add a new text, voice, category, announcement, forum, or stage channel to a Discord server by specifying its name, type, and server ID.
Instructions
Create a new channel in a Discord server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| name | Yes | Name of the new channel | |
| type | Yes | Type of channel | |
| parentId | No | ID of the parent category | |
| topic | No | Channel topic (text channels only) | |
| nsfw | No | Whether the channel is NSFW | |
| bitrate | No | Bitrate for voice channels | |
| userLimit | No | User limit for voice channels | |
| rateLimitPerUser | No | Slowmode in seconds | |
| position | No | Position of the channel | |
| reason | No | Reason for creating the channel |
Implementation Reference
- src/tools/channel-tools.ts:138-170 (handler)The handler function for the create_channel tool. It fetches the Discord guild, constructs channel creation options based on input parameters (mapping type string to ChannelType enum), removes undefined options, creates the channel using guild.channels.create(), handles errors with withErrorHandling, and returns JSON-formatted response with new channel details.async ({ guildId, name, type, parentId, topic, nsfw, bitrate, userLimit, rateLimitPerUser, position, reason }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channelOptions: Record<string, unknown> = { name, type: channelTypeMap[type], parent: parentId, topic, nsfw, bitrate, userLimit, rateLimitPerUser, position, reason, }; // Remove undefined values Object.keys(channelOptions).forEach((key) => { if (channelOptions[key] === undefined) delete channelOptions[key]; }); const newChannel = await guild.channels.create(channelOptions as any); return { id: newChannel.id, name: newChannel.name, type: ChannelType[newChannel.type], message: 'Channel created' }; }); 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/channel-tools.ts:125-137 (schema)Zod input schema for create_channel tool, validating parameters like guildId, name, type (enum of channel types), and optional fields for customization.{ guildId: z.string().describe('The ID of the server (guild)'), name: z.string().describe('Name of the new channel'), type: z.enum(['text', 'voice', 'category', 'announcement', 'forum', 'stage']).describe('Type of channel'), parentId: z.string().optional().describe('ID of the parent category'), topic: z.string().optional().describe('Channel topic (text channels only)'), nsfw: z.boolean().optional().describe('Whether the channel is NSFW'), bitrate: z.number().optional().describe('Bitrate for voice channels'), userLimit: z.number().optional().describe('User limit for voice channels'), rateLimitPerUser: z.number().optional().describe('Slowmode in seconds'), position: z.number().optional().describe('Position of the channel'), reason: z.string().optional().describe('Reason for creating the channel'), },
- src/tools/channel-tools.ts:122-170 (registration)Full registration of the create_channel tool using server.tool(), including name, description, input schema, and inline handler function.server.tool( 'create_channel', 'Create a new channel in a Discord server', { guildId: z.string().describe('The ID of the server (guild)'), name: z.string().describe('Name of the new channel'), type: z.enum(['text', 'voice', 'category', 'announcement', 'forum', 'stage']).describe('Type of channel'), parentId: z.string().optional().describe('ID of the parent category'), topic: z.string().optional().describe('Channel topic (text channels only)'), nsfw: z.boolean().optional().describe('Whether the channel is NSFW'), bitrate: z.number().optional().describe('Bitrate for voice channels'), userLimit: z.number().optional().describe('User limit for voice channels'), rateLimitPerUser: z.number().optional().describe('Slowmode in seconds'), position: z.number().optional().describe('Position of the channel'), reason: z.string().optional().describe('Reason for creating the channel'), }, async ({ guildId, name, type, parentId, topic, nsfw, bitrate, userLimit, rateLimitPerUser, position, reason }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channelOptions: Record<string, unknown> = { name, type: channelTypeMap[type], parent: parentId, topic, nsfw, bitrate, userLimit, rateLimitPerUser, position, reason, }; // Remove undefined values Object.keys(channelOptions).forEach((key) => { if (channelOptions[key] === undefined) delete channelOptions[key]; }); const newChannel = await guild.channels.create(channelOptions as any); return { id: newChannel.id, name: newChannel.name, type: ChannelType[newChannel.type], message: 'Channel created' }; }); 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:55-55 (registration)Top-level registration call to registerChannelTools(server), which includes the create_channel tool registration.registerChannelTools(server);