Send Discord Message
discord_send_messageSend text messages or rich embeds to Discord channels via webhook. Supports threads, TTS, and custom usernames.
Instructions
Discordチャンネルにメッセージを送信します。
content、embedsのいずれか最低1つが必要です。 環境変数DISCORD_WEBHOOK_URLに設定されたWebhookを使用します。
⚠️ レート制限: 30メッセージ/分/チャンネル
Args:
content (string, optional): メッセージ内容(1-2000文字)
username (string, optional): Webhookのユーザー名を上書き(最大80文字)
avatar_url (string, optional): Webhookのアバター画像をURLで指定
tts (boolean, optional): テキスト読み上げ(TTS)メッセージとして送信(デフォルト: false)
embeds (array, optional): Embedの配列(最大10個、合計6000文字以内)
allowed_mentions (object, optional): 許可されたメンション設定
thread_id (string, optional): 送信先スレッドID(指定したスレッドに送信、スレッドは自動アーカイブ解除)
thread_name (string, optional): 作成するスレッド名(フォーラム/メディアチャンネルのみで新しいスレッドを作成、最大100文字)
Returns: { "success": boolean, // 送信が成功したか "message_id": string, // 送信されたメッセージのID "channel_id": string, // 送信先チャンネルID "timestamp": string // 送信日時 (ISO 8601形式) }
Examples:
シンプルなテキスト送信: { "content": "Hello, Discord!" }
Embed付き送信: { "embeds": [{ "title": "タイトル", "description": "説明", "color": 0x00FF00 }] }
スレッドに送信: { "content": "スレッドメッセージ", "thread_id": "123456789" }
Error Handling:
"Validation error: content/embeds - content、embeds のうち最低1つを指定してください"
"Discord Webhook error: 400 Bad Request - Invalid webhook URL"
"Discord Webhook error: 404 Not Found - Webhook not found"
"Discord Webhook error: レート制限に達しました" - 429エラー時、retry-after秒後に再試行
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | メッセージ内容 (最大2000文字) | |
| username | No | Webhookのユーザー名を上書き | |
| avatar_url | No | WebhookのアバターURLを上書き | |
| tts | No | テキスト読み上げ (TTS) | |
| embeds | No | Embedの配列 (最大10個) | |
| allowed_mentions | No | 許可されたメンション設定 | |
| thread_id | No | 送信先スレッドID (自動アーカイブ解除) | |
| thread_name | No | 作成するスレッド名 (フォーラム/メディアチャンネルのみ) |
Implementation Reference
- src/index.ts:42-153 (handler)The handler function for discord_send_message tool. Validates that content or embeds is present, builds the payload, calls sendToDiscord() with wait=true and optional thread_id, and returns the response with message_id, channel_id, and timestamp.
server.registerTool( "discord_send_message", { title: "Send Discord Message", description: `Discordチャンネルにメッセージを送信します。 content、embedsのいずれか最低1つが必要です。 環境変数DISCORD_WEBHOOK_URLに設定されたWebhookを使用します。 ⚠️ レート制限: 30メッセージ/分/チャンネル Args: - content (string, optional): メッセージ内容(1-2000文字) - username (string, optional): Webhookのユーザー名を上書き(最大80文字) - avatar_url (string, optional): Webhookのアバター画像をURLで指定 - tts (boolean, optional): テキスト読み上げ(TTS)メッセージとして送信(デフォルト: false) - embeds (array, optional): Embedの配列(最大10個、合計6000文字以内) - allowed_mentions (object, optional): 許可されたメンション設定 - thread_id (string, optional): 送信先スレッドID(指定したスレッドに送信、スレッドは自動アーカイブ解除) - thread_name (string, optional): 作成するスレッド名(フォーラム/メディアチャンネルのみで新しいスレッドを作成、最大100文字) Returns: { "success": boolean, // 送信が成功したか "message_id": string, // 送信されたメッセージのID "channel_id": string, // 送信先チャンネルID "timestamp": string // 送信日時 (ISO 8601形式) } Examples: - シンプルなテキスト送信: { "content": "Hello, Discord!" } - Embed付き送信: { "embeds": [{ "title": "タイトル", "description": "説明", "color": 0x00FF00 }] } - スレッドに送信: { "content": "スレッドメッセージ", "thread_id": "123456789" } Error Handling: - "Validation error: content/embeds - content、embeds のうち最低1つを指定してください" - "Discord Webhook error: 400 Bad Request - Invalid webhook URL" - "Discord Webhook error: 404 Not Found - Webhook not found" - "Discord Webhook error: レート制限に達しました" - 429エラー時、retry-after秒後に再試行`, inputSchema: SendMessageSchema, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true, }, }, async (params: SendMessageInput) => { // content, embeds のうち1つが必要 const hasContent = params.content && params.content.length > 0; const hasEmbeds = params.embeds && params.embeds.length > 0; if (!hasContent && !hasEmbeds) { return { content: [ { type: "text", text: "エラー: content、embeds のうち最低1つを指定してください", }, ], isError: true, }; } // payloadの構築 const payload: Record<string, unknown> = {}; if (hasContent) payload.content = params.content; if (params.username) payload.username = params.username; if (params.avatar_url) payload.avatar_url = params.avatar_url; if (params.tts) payload.tts = params.tts; if (hasEmbeds) payload.embeds = params.embeds; if (params.allowed_mentions) payload.allowed_mentions = params.allowed_mentions; if (params.thread_name) payload.thread_name = params.thread_name; // メッセージ送信(wait=trueでメッセージIDを取得) const { result, error } = await sendToDiscord( payload, true, params.thread_id ); if (error) { return { content: [ { type: "text", text: `エラー: ${formatError(error)}`, }, ], isError: true, }; } const messageInfo = result; return { content: [ { type: "text", text: messageInfo ? `メッセージを送信しました\nID: ${messageInfo.id}\nチャンネル: ${messageInfo.channel_id}` : "メッセージを送信しました", }, ], structuredContent: { success: true, message_id: messageInfo?.id, channel_id: messageInfo?.channel_id, timestamp: messageInfo?.timestamp, }, }; } - src/schemas.ts:58-72 (schema)Zod input validation schema for discord_send_message. Defines all allowed fields: content, username, avatar_url, tts, embeds, allowed_mentions, thread_id, thread_name.
export const SendMessageSchema = z.object({ content: z .string() .min(1) .max(MAX_CONTENT_LENGTH) .optional() .describe(`メッセージ内容 (最大${MAX_CONTENT_LENGTH}文字)`), username: z.string().max(80).optional().describe("Webhookのユーザー名を上書き"), avatar_url: z.string().url().optional().describe("WebhookのアバターURLを上書き"), tts: z.boolean().optional().default(false).describe("テキスト読み上げ (TTS)"), embeds: z.array(EmbedSchema).max(MAX_EMBEDS).optional().describe(`Embedの配列 (最大${MAX_EMBEDS}個)`), allowed_mentions: AllowedMentionsSchema.optional().describe("許可されたメンション設定"), thread_id: z.string().optional().describe("送信先スレッドID (自動アーカイブ解除)"), thread_name: z.string().max(100).optional().describe("作成するスレッド名 (フォーラム/メディアチャンネルのみ)"), }).strict(); - src/index.ts:42-89 (registration)Registration of discord_send_message tool via server.registerTool with tool name, metadata (title, description, inputSchema, annotations), and the handler callback.
server.registerTool( "discord_send_message", { title: "Send Discord Message", description: `Discordチャンネルにメッセージを送信します。 content、embedsのいずれか最低1つが必要です。 環境変数DISCORD_WEBHOOK_URLに設定されたWebhookを使用します。 ⚠️ レート制限: 30メッセージ/分/チャンネル Args: - content (string, optional): メッセージ内容(1-2000文字) - username (string, optional): Webhookのユーザー名を上書き(最大80文字) - avatar_url (string, optional): Webhookのアバター画像をURLで指定 - tts (boolean, optional): テキスト読み上げ(TTS)メッセージとして送信(デフォルト: false) - embeds (array, optional): Embedの配列(最大10個、合計6000文字以内) - allowed_mentions (object, optional): 許可されたメンション設定 - thread_id (string, optional): 送信先スレッドID(指定したスレッドに送信、スレッドは自動アーカイブ解除) - thread_name (string, optional): 作成するスレッド名(フォーラム/メディアチャンネルのみで新しいスレッドを作成、最大100文字) Returns: { "success": boolean, // 送信が成功したか "message_id": string, // 送信されたメッセージのID "channel_id": string, // 送信先チャンネルID "timestamp": string // 送信日時 (ISO 8601形式) } Examples: - シンプルなテキスト送信: { "content": "Hello, Discord!" } - Embed付き送信: { "embeds": [{ "title": "タイトル", "description": "説明", "color": 0x00FF00 }] } - スレッドに送信: { "content": "スレッドメッセージ", "thread_id": "123456789" } Error Handling: - "Validation error: content/embeds - content、embeds のうち最低1つを指定してください" - "Discord Webhook error: 400 Bad Request - Invalid webhook URL" - "Discord Webhook error: 404 Not Found - Webhook not found" - "Discord Webhook error: レート制限に達しました" - 429エラー時、retry-after秒後に再試行`, inputSchema: SendMessageSchema, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true, }, }, - src/discord-api.ts:124-151 (helper)Helper function sendToDiscord that sends the payload to the Discord webhook URL via POST request. Handles wait parameter and thread_id query parameter.
export async function sendToDiscord( payload: { content?: string; username?: string; avatar_url?: string; tts?: boolean; embeds?: Embed[]; allowed_mentions?: AllowedMentions; thread_name?: string; }, wait: boolean = true, threadId?: string ): Promise<{ result: DiscordMessageResponse | null; error?: DiscordWebhookError }> { const url = new URL(WEBHOOK_URL!); if (wait) url.searchParams.set("wait", "true"); if (threadId) url.searchParams.set("thread_id", threadId); try { const result = await makeRequest<DiscordMessageResponse | null>( url.toString(), "POST", payload ); return { result }; } catch (error) { return { result: null, error: convertError(error) }; } }