Skip to main content
Glama
scarecr0w12

discord-mcp

delete_channel

Remove a channel from a Discord server by specifying the server and channel IDs. Provide an optional reason for the deletion.

Instructions

Delete a channel from a Discord server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the channel to delete
reasonNoReason for deleting the channel

Implementation Reference

  • The core handler function for the 'delete_channel' tool. It fetches the Discord guild and channel using the provided IDs, deletes the channel (optionally with a reason), and returns a success message with channel details or an error.
    async ({ guildId, channelId, 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 (!channel) throw new Error('Channel not found');
    
        const channelName = channel.name;
        await channel.delete(reason);
        return { channelId, channelName, message: 'Channel 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) }] };
    }
  • Zod input schema defining the parameters for the 'delete_channel' tool: required guildId and channelId, optional reason.
    {
      guildId: z.string().describe('The ID of the server (guild)'),
      channelId: z.string().describe('The ID of the channel to delete'),
      reason: z.string().optional().describe('Reason for deleting the channel'),
    },
  • src/index.ts:55-55 (registration)
    Top-level registration call in the main server setup that invokes registerChannelTools, which in turn registers the 'delete_channel' tool via server.tool().
    registerChannelTools(server);
  • Direct registration of the 'delete_channel' tool using server.tool(), including name, description, schema, and handler within the registerChannelTools function.
    // Delete a channel
    server.tool(
      'delete_channel',
      'Delete a channel from a Discord server',
      {
        guildId: z.string().describe('The ID of the server (guild)'),
        channelId: z.string().describe('The ID of the channel to delete'),
        reason: z.string().optional().describe('Reason for deleting the channel'),
      },
      async ({ guildId, channelId, 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 (!channel) throw new Error('Channel not found');
    
          const channelName = channel.name;
          await channel.delete(reason);
          return { channelId, channelName, message: 'Channel 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) }] };
      }
    );

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