discord_delete_message
Remove a specific message in a Discord text channel by specifying the channel and message IDs, ensuring clean and organized communication management.
Instructions
Deletes a specific message from a Discord text channel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channelId | Yes | ||
| messageId | Yes | ||
| reason | No |
Implementation Reference
- src/tools/reactions.ts:171-213 (handler)The main handler function for the discord_delete_message tool. It validates arguments using DeleteMessageSchema, checks client readiness, fetches the channel and message, deletes the message, and returns success or error response.export async function deleteMessageHandler( args: unknown, context: ToolContext ): Promise<ToolResponse> { const { channelId, messageId, reason } = DeleteMessageSchema.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() || !('messages' in channel)) { return { content: [{ type: "text", text: `Cannot find text channel with ID: ${channelId}` }], isError: true }; } // Fetch the message const message = await channel.messages.fetch(messageId); if (!message) { return { content: [{ type: "text", text: `Cannot find message with ID: ${messageId}` }], isError: true }; } // Delete the message await message.delete(); return { content: [{ type: "text", text: `Successfully deleted message with ID: ${messageId} from channel: ${channelId}` }] }; } catch (error) { return handleDiscordError(error); } }
- src/schemas.ts:98-102 (schema)Zod schema for input validation used within the deleteMessageHandler.export const DeleteMessageSchema = z.object({ channelId: z.string(), messageId: z.string(), reason: z.string().optional() });
- src/toolList.ts:225-237 (schema)JSON Schema definition for the tool's input parameters, used in the MCP listTools response.{ name: "discord_delete_message", description: "Deletes a specific message from a Discord text channel", inputSchema: { type: "object", properties: { channelId: { type: "string" }, messageId: { type: "string" }, reason: { type: "string" } }, required: ["channelId", "messageId"] } },
- src/server.ts:158-161 (registration)Registration and dispatching logic in the MCP server's CallToolRequest handler switch statement.case "discord_delete_message": this.logClientState("before discord_delete_message handler"); toolResponse = await deleteMessageHandler(args, this.toolContext); return toolResponse;