discord_create_webhook
Create a Discord webhook to automate messages in a specific channel by providing a channel ID and webhook name using the MCP-Discord server.
Instructions
Creates a new webhook for a Discord channel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| avatar | No | ||
| channelId | Yes | ||
| name | Yes | ||
| reason | No |
Implementation Reference
- src/tools/webhooks.ts:12-57 (handler)The primary handler function implementing the discord_create_webhook tool. It validates input with Zod, fetches the Discord channel, verifies webhook support, creates the webhook using discord.js, and returns the webhook ID and token on success or appropriate error.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 || !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: name, avatar: avatar, reason: reason }); return { content: [{ type: "text", text: `Successfully created webhook with ID: ${webhook.id} and token: ${webhook.token}` }] }; } catch (error) { return handleDiscordError(error); } }
- src/server.ts:163-166 (registration)Tool dispatch/registration in the MCP server request handler switch statement, calling the createWebhookHandler with parsed arguments and tool context.case "discord_create_webhook": this.logClientState("before discord_create_webhook handler"); toolResponse = await createWebhookHandler(args, this.toolContext); return toolResponse;
- src/toolList.ts:238-251 (schema)MCP tool metadata including name, description, and JSON schema for input validation, used in listTools response.{ 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/schemas.ts:104-109 (schema)Zod schema for input validation used within the handler to parse and type-check arguments.export const CreateWebhookSchema = z.object({ channelId: z.string(), name: z.string(), avatar: z.string().optional(), reason: z.string().optional() });