bulk_delete_messages
Delete multiple Discord messages at once from a channel, 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 that performs bulk deletion of messages in a Discord channel using channel.bulkDelete(), with error handling and channel type validation.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 for validating guildId, channelId, array of messageIds, and 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)Tool registration using server.tool() inside registerMessageTools function, which is called from index.ts.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 validate if a channel is messageable, used in the bulk_delete_messages 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:58-58 (registration)Call to registerMessageTools(server) which includes the bulk_delete_messages tool registration among other message tools.registerMessageTools(server);