discord_delete_message
Delete specific messages from Discord text channels to manage content and maintain channel organization.
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:214-265 (handler)The core handler function that implements the discord_delete_message tool. It validates input with Zod schema, fetches the channel and message using Discord.js, and deletes the message.export async function deleteMessageHandler( args: unknown, context: ToolContext ): Promise<ToolResponse> { const { channelId, messageId } = 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?.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/tool-list.ts:229-241 (schema)MCP tool definition including name, description, and input schema used for tool registration and client-side validation.{ 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/schemas.ts:97-101 (schema)Zod schema for server-side input validation of the discord_delete_message tool parameters.export const DeleteMessageSchema = z.object({ channelId: z.string(), messageId: z.string(), reason: z.string().optional(), });
- src/server.ts:181-184 (registration)Tool handler registration in the main server switch statement that routes tool calls to the deleteMessageHandler.case 'discord_delete_message': this.logClientState('before discord_delete_message handler'); toolResponse = await deleteMessageHandler(args, this.toolContext); return toolResponse;
- src/transport.ts:364-365 (registration)Tool handler registration in the transport layer switch statement for HTTP transport handling.case 'discord_delete_message': result = await deleteMessageHandler(params, this.toolContext!);