discord_delete_message
Delete a specific message from a Discord text channel using channel ID, message ID, and an optional reason.
Instructions
Deletes a specific message from a Discord text channel
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channelId | Yes | ||
| messageId | Yes | ||
| reason | No |
Implementation Reference
- src/tools/reactions.ts:213-265 (handler)The deleteMessageHandler function that executes the delete message logic. It parses args with DeleteMessageSchema, fetches the channel, fetches the message, and calls message.delete().
// Delete message handler 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/schemas.ts:97-101 (schema)DeleteMessageSchema - Zod schema defining the input validation for discord_delete_message tool: channelId (string), messageId (string), and optional reason (string).
export const DeleteMessageSchema = z.object({ channelId: z.string(), messageId: z.string(), reason: z.string().optional(), }); - src/tool-list.ts:229-241 (registration)Registration entry in tool-list.ts for 'discord_delete_message' with name, description, and inputSchema (channelId, messageId, reason - channelId and messageId required).
{ 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:181-184 (registration)Case statement in server.ts that routes 'discord_delete_message' to the deleteMessageHandler function.
case 'discord_delete_message': this.logClientState('before discord_delete_message handler'); toolResponse = await deleteMessageHandler(args, this.toolContext); return toolResponse; - src/transport.ts:364-366 (registration)Case statement in transport.ts that routes 'discord_delete_message' to deleteMessageHandler.
case 'discord_delete_message': result = await deleteMessageHandler(params, this.toolContext!); break;