delete_channel
Remove a channel from a Discord server by specifying the server and channel IDs. This tool helps manage server structure by deleting unnecessary or outdated channels.
Instructions
Delete a channel from a Discord server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| channelId | Yes | The ID of the channel to delete | |
| reason | No | Reason for deleting the channel |
Implementation Reference
- src/tools/channel-tools.ts:182-199 (handler)The handler function that fetches the Discord guild and channel, then deletes the channel using channel.delete(reason), wrapped in error handling with withErrorHandling.async ({ guildId, channelId, 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) throw new Error('Channel not found'); const channelName = channel.name; await channel.delete(reason); return { channelId, channelName, message: 'Channel deleted 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/channel-tools.ts:177-181 (schema)Zod schema defining input parameters: guildId (required string), channelId (required string), reason (optional string).{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel to delete'), reason: z.string().optional().describe('Reason for deleting the channel'), },
- src/tools/channel-tools.ts:174-200 (registration)MCP tool registration call to server.tool with name 'delete_channel', description, input schema, and handler function.server.tool( 'delete_channel', 'Delete a channel from a Discord server', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel to delete'), reason: z.string().optional().describe('Reason for deleting the channel'), }, async ({ guildId, channelId, 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) throw new Error('Channel not found'); const channelName = channel.name; await channel.delete(reason); return { channelId, channelName, message: 'Channel deleted 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:54-54 (registration)Invocation of registerChannelTools which registers the delete_channel tool among others.registerChannelTools(server);
- src/index.ts:12-12 (registration)Import of the registerChannelTools function that contains the delete_channel tool registration.import { registerChannelTools } from './tools/channel-tools.js';