discord_create_webhook
Create a Discord webhook to automate messages in a specific channel. Provide channel ID and webhook name to set up automated notifications or integrations.
Instructions
Creates a new webhook for a Discord channel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channelId | Yes | ||
| name | Yes | ||
| avatar | No | ||
| reason | No |
Implementation Reference
- src/tools/webhooks.ts:11-68 (handler)The core handler function that implements the discord_create_webhook tool. It validates input using CreateWebhookSchema, fetches the channel, checks permissions, creates the webhook using discord.js channel.createWebhook, and returns success/error response.export async function createWebhookHandler( args: unknown, context: ToolContext ): Promise<ToolResponse> { const { channelId, name, avatar, reason } = CreateWebhookSchema.parse(args); try { if (!context.client.isReady()) { return { content: [{ type: 'text', text: 'Discord client not logged in.' }], isError: true, }; } const channel = await context.client.channels.fetch(channelId); if (!channel?.isTextBased()) { return { content: [ { type: 'text', text: `Cannot find text channel with ID: ${channelId}`, }, ], isError: true, }; } // Check if the channel supports webhooks if (!('createWebhook' in channel)) { return { content: [ { type: 'text', text: `Channel type does not support webhooks: ${channelId}`, }, ], isError: true, }; } // Create the webhook const webhook = await channel.createWebhook({ name, avatar, reason, }); return { content: [ { type: 'text', text: `Successfully created webhook with ID: ${webhook.id} and token: ${webhook.token}`, }, ], }; } catch (error) { return handleDiscordError(error); } }
- src/schemas.ts:103-108 (schema)Zod schema for validating input parameters of the discord_create_webhook tool: channelId (required), name (required), avatar (optional), reason (optional). Used in the handler for parsing args.export const CreateWebhookSchema = z.object({ channelId: z.string(), name: z.string(), avatar: z.string().optional(), reason: z.string().optional(), });
- src/tool-list.ts:242-255 (registration)Tool registration entry in the toolList array, defining name, description, and inputSchema. This is returned by list_tools endpoint.{ name: 'discord_create_webhook', description: 'Creates a new webhook for a Discord channel', inputSchema: { type: 'object', properties: { channelId: { type: 'string' }, name: { type: 'string' }, avatar: { type: 'string' }, reason: { type: 'string' }, }, required: ['channelId', 'name'], }, },
- src/server.ts:186-189 (registration)Switch case in DiscordMCPServer that dispatches 'discord_create_webhook' calls to the createWebhookHandler function.case 'discord_create_webhook': this.logClientState('before discord_create_webhook handler'); toolResponse = await createWebhookHandler(args, this.toolContext); return toolResponse;
- src/tools/tools.ts:27-31 (helper)Re-export of the webhook handlers, including createWebhookHandler, allowing centralized imports from './tools/tools.js' used in server.ts and transport.ts.createWebhookHandler, deleteWebhookHandler, editWebhookHandler, sendWebhookMessageHandler, } from './webhooks.js';