bulk_delete_messages
Remove multiple messages from a Discord channel at once, supporting up to 100 messages that are less than 14 days old.
Instructions
Bulk delete messages from a channel (up to 100, messages must be < 14 days old)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| channelId | Yes | The ID of the channel | |
| messageIds | Yes | Array of message IDs to delete | |
| reason | No | Reason for deletion |
Implementation Reference
- src/tools/message-tools.ts:195-214 (handler)Handler function executes bulk delete: fetches Discord client, guild, channel; validates channel type; bulkDeletes up to 100 messages; handles errors with withErrorHandling; returns JSON response.async ({ guildId, channelId, messageIds, reason }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!isMessageableChannel(channel)) { throw new Error('Channel does not support messages'); } const deleted = await channel.bulkDelete(messageIds.slice(0, 100)); return { deletedCount: deleted.size, message: 'Messages deleted successfully' }; }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; }
- src/tools/message-tools.ts:189-194 (schema)Input schema using Zod: requires guildId, channelId, messageIds (string array); optional reason.{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), messageIds: z.array(z.string()).describe('Array of message IDs to delete'), reason: z.string().optional().describe('Reason for deletion'), },
- src/tools/message-tools.ts:186-215 (registration)Full registration of the bulk_delete_messages tool using McpServer.tool() with name, description, schema, and handler.server.tool( 'bulk_delete_messages', 'Bulk delete messages from a channel (up to 100, messages must be < 14 days old)', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), messageIds: z.array(z.string()).describe('Array of message IDs to delete'), reason: z.string().optional().describe('Reason for deletion'), }, async ({ guildId, channelId, messageIds, reason }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!isMessageableChannel(channel)) { throw new Error('Channel does not support messages'); } const deleted = await channel.bulkDelete(messageIds.slice(0, 100)); return { deletedCount: deleted.size, message: 'Messages deleted successfully' }; }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } );
- src/tools/message-tools.ts:9-17 (helper)Helper function to type-guard if a channel is messageable (TextChannel, NewsChannel, or ThreadChannel). Used in the handler.function isMessageableChannel(channel: unknown): channel is MessageableChannel { if (!channel || typeof channel !== 'object') return false; const ch = channel as { type?: number }; return ch.type === ChannelType.GuildText || ch.type === ChannelType.GuildAnnouncement || ch.type === ChannelType.PublicThread || ch.type === ChannelType.PrivateThread || ch.type === ChannelType.AnnouncementThread; }
- src/index.ts:59-59 (registration)Top-level call to registerMessageTools(server), which registers bulk_delete_messages among other message tools.registerMessageTools(server);