Skip to main content
Glama

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
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the channel
messageIdsYesArray of message IDs to delete
reasonNoReason for deletion

Implementation Reference

  • 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) }] }; }
  • 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'), },
  • 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) }] }; } );
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/scarecr0w12/discord-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server