discord_send_webhook_message
Send messages to a Discord channel using a webhook. Configure webhook details, content, username, avatar, and thread ID for precise message delivery.
Instructions
Sends a message to a Discord channel using a webhook
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| avatarURL | No | ||
| content | Yes | ||
| threadId | No | ||
| username | No | ||
| webhookId | Yes | ||
| webhookToken | Yes |
Implementation Reference
- src/tools/webhooks.ts:60-98 (handler)The core handler function that validates input using SendWebhookMessageSchema, fetches the Discord webhook, sends the message with provided content and options, handles errors, and returns appropriate ToolResponse.export async function sendWebhookMessageHandler( args: unknown, context: ToolContext ): Promise<ToolResponse> { const { webhookId, webhookToken, content, username, avatarURL, threadId } = SendWebhookMessageSchema.parse(args); try { if (!context.client.isReady()) { return { content: [{ type: "text", text: "Discord client not logged in." }], isError: true }; } const webhook = await context.client.fetchWebhook(webhookId, webhookToken); if (!webhook) { return { content: [{ type: "text", text: `Cannot find webhook with ID: ${webhookId}` }], isError: true }; } // Send the message await webhook.send({ content: content, username: username, avatarURL: avatarURL, threadId: threadId }); return { content: [{ type: "text", text: `Successfully sent webhook message to webhook ID: ${webhookId}` }] }; } catch (error) { return handleDiscordError(error); } }
- src/server.ts:168-171 (registration)Switch case in server that registers and dispatches calls to the sendWebhookMessageHandler function.case "discord_send_webhook_message": this.logClientState("before discord_send_webhook_message handler"); toolResponse = await sendWebhookMessageHandler(args, this.toolContext); return toolResponse;
- src/toolList.ts:252-267 (schema)MCP tool definition including name, description, and input schema for registration in the tool list.{ name: "discord_send_webhook_message", description: "Sends a message to a Discord channel using a webhook", inputSchema: { type: "object", properties: { webhookId: { type: "string" }, webhookToken: { type: "string" }, content: { type: "string" }, username: { type: "string" }, avatarURL: { type: "string" }, threadId: { type: "string" } }, required: ["webhookId", "webhookToken", "content"] } },
- src/schemas.ts:111-118 (schema)Zod validation schema for the tool inputs, used inside the handler for parsing arguments.export const SendWebhookMessageSchema = z.object({ webhookId: z.string(), webhookToken: z.string(), content: z.string(), username: z.string().optional(), avatarURL: z.string().optional(), threadId: z.string().optional() });