discord_send_webhook_message
Send a message to a Discord channel through a webhook. Customize content, username, avatar, or thread ID for targeted notifications.
Instructions
Sends a message to a Discord channel using a webhook
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| webhookId | Yes | ||
| webhookToken | Yes | ||
| content | Yes | ||
| username | No | ||
| avatarURL | No | ||
| threadId | No |
Implementation Reference
- src/tools/webhooks.ts:70-114 (handler)The main handler function that sends a message via Discord webhook. Parses args with SendWebhookMessageSchema, fetches the webhook, and sends the message with content, username, avatarURL, and threadId.
// Send webhook message handler 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, username, avatarURL, threadId, }); return { content: [ { type: 'text', text: `Successfully sent webhook message to webhook ID: ${webhookId}`, }, ], }; } catch (error) { return handleDiscordError(error); } } - src/schemas.ts:110-117 (schema)Zod schema defining input validation for sendWebhookMessage: webhookId (string), webhookToken (string), content (string), and optional username, avatarURL, threadId.
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(), }); - src/tool-list.ts:256-270 (registration)Tool registration entry defining the tool name 'discord_send_webhook_message', description, inputSchema with required fields webhookId, webhookToken, and content.
{ 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/tools/tools.ts:25-31 (helper)Re-exports the sendWebhookMessageHandler from webhooks.ts as a barrel export.
export { ToolContext, ToolHandler, ToolResponse } from './types.js'; export { createWebhookHandler, deleteWebhookHandler, editWebhookHandler, sendWebhookMessageHandler, } from './webhooks.js'; - src/server.ts:191-197 (registration)Server route dispatch: maps the 'discord_send_webhook_message' case to calling sendWebhookMessageHandler(args, toolContext).
case 'discord_send_webhook_message': this.logClientState('before discord_send_webhook_message handler'); toolResponse = await sendWebhookMessageHandler( args, this.toolContext ); return toolResponse;