Skip to main content
Glama
scarecr0w12

discord-mcp

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

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