discord_send_dm
Send a private direct message to a Discord user via their user ID. The bot must share a server with the target user. Provide the user ID and message content.
Instructions
Send a direct message to a user by their user ID. The bot must share at least one server with the user.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | Yes | The Discord user ID. | |
| content | Yes | The message content to send. |
Implementation Reference
- src/tools/dm.ts:175-179 (handler)Handler for discord_send_dm: fetches the user by ID, sends a DM with the provided content, and returns a success message with the message ID.
case "discord_send_dm": { const user = await discord.users.fetch(validateId(args.user_id, "user_id")); const sent = await user.send(args.content as string); return { content: [{ type: "text", text: `✅ DM sent to ${user.username} (message id: ${sent.id}).` }] }; } - src/tools/dm.ts:71-82 (schema)Schema definition for discord_send_dm: requires user_id (string) and content (string).
{ name: "discord_send_dm", description: "Send a direct message to a user by their user ID. The bot must share at least one server with the user.", inputSchema: { type: "object", properties: { ...userIdProp, content: { type: "string", description: "The message content to send." }, }, required: ["user_id", "content"], }, - src/tools/index.ts:60-66 (registration)Tool routing function that iterates over all modules (including dm) and delegates to the correct handler.
export async function handleTool(name: string, args: Record<string, unknown>): Promise<ToolResult> { for (const mod of modules) { const result = await mod.handle(name, args); if (result) return result; } throw new Error(`Unknown tool: ${name}`); } - src/tools/index.ts:26-43 (registration)The dm module is imported and added to the modules array, registering all its tool definitions (including discord_send_dm).
import dm from "./dm.js"; const modules: ToolModule[] = [ discovery, messages, channels, permissions, members, roles, moderation, screening, stats, forums, webhooks, scheduledEvents, invites, dm, ]; - src/client.ts:97-101 (helper)validateId helper used by the handler to validate Discord snowflake IDs before making API calls.
export function validateId(value: unknown, label: string): string { const id = String(value ?? ""); if (!/^\d{17,20}$/.test(id)) throw new Error(`Invalid ${label}: "${id}". Must be a Discord snowflake ID (17-20 digits).`); return id; }