Skip to main content
Glama
scarecr0w12

discord-mcp

list_channel_webhooks

Retrieve all webhooks configured in a Discord channel to manage integrations and automate messaging.

Instructions

List all webhooks in a channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the channel

Implementation Reference

  • The core handler function for the 'list_channel_webhooks' tool. It fetches the Discord client, guild, and channel, validates the channel type, retrieves all webhooks from the channel, maps their properties (redacting tokens), wraps in error handling, and returns a JSON-formatted response.
    async ({ guildId, channelId }) => {
      const result = await withErrorHandling(async () => {
        const client = await getDiscordClient();
        const guild = await client.guilds.fetch(guildId);
        const channel = await guild.channels.fetch(channelId);
        
        if (!isWebhookableChannel(channel)) {
          throw new Error('Channel does not support webhooks');
        }
    
        const webhooks = await channel.fetchWebhooks();
        return webhooks.map((wh) => ({
          id: wh.id,
          name: wh.name,
          type: wh.type,
          channelId: wh.channelId,
          guildId: wh.guildId,
          avatar: wh.avatar,
          token: wh.token ? '[REDACTED]' : null,
          owner: wh.owner ? { id: wh.owner.id, username: wh.owner.username } : null,
          applicationId: wh.applicationId,
          sourceGuild: wh.sourceGuild ? { id: wh.sourceGuild.id, name: wh.sourceGuild.name } : null,
          sourceChannel: wh.sourceChannel ? { id: wh.sourceChannel.id, name: wh.sourceChannel.name } : null,
          url: wh.url,
          createdAt: wh.createdAt?.toISOString(),
        }));
      });
    
      if (!result.success) {
        return { content: [{ type: 'text', text: result.error }], isError: true };
      }
    
      return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
    }
  • The registration of the 'list_channel_webhooks' tool using McpServer.tool(), including the tool name, description, input schema (guildId and channelId), and the handler function.
    server.tool(
      'list_channel_webhooks',
      'List all webhooks in a channel',
      {
        guildId: z.string().describe('The ID of the server (guild)'),
        channelId: z.string().describe('The ID of the channel'),
      },
      async ({ guildId, channelId }) => {
        const result = await withErrorHandling(async () => {
          const client = await getDiscordClient();
          const guild = await client.guilds.fetch(guildId);
          const channel = await guild.channels.fetch(channelId);
          
          if (!isWebhookableChannel(channel)) {
            throw new Error('Channel does not support webhooks');
          }
    
          const webhooks = await channel.fetchWebhooks();
          return webhooks.map((wh) => ({
            id: wh.id,
            name: wh.name,
            type: wh.type,
            channelId: wh.channelId,
            guildId: wh.guildId,
            avatar: wh.avatar,
            token: wh.token ? '[REDACTED]' : null,
            owner: wh.owner ? { id: wh.owner.id, username: wh.owner.username } : null,
            applicationId: wh.applicationId,
            sourceGuild: wh.sourceGuild ? { id: wh.sourceGuild.id, name: wh.sourceGuild.name } : null,
            sourceChannel: wh.sourceChannel ? { id: wh.sourceChannel.id, name: wh.sourceChannel.name } : null,
            url: wh.url,
            createdAt: wh.createdAt?.toISOString(),
          }));
        });
    
        if (!result.success) {
          return { content: [{ type: 'text', text: result.error }], isError: true };
        }
    
        return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
      }
    );
  • Zod schema defining the input parameters for the tool: guildId (string) and channelId (string).
      guildId: z.string().describe('The ID of the server (guild)'),
      channelId: z.string().describe('The ID of the channel'),
    },
  • Helper function to type-guard and check if a Discord channel supports webhooks (Text, News, Voice, Forum channels). Used in the handler to validate the channel.
    function isWebhookableChannel(channel: unknown): channel is WebhookableChannel {
      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.GuildVoice ||
             ch.type === ChannelType.GuildForum;
    }
  • src/index.ts:60-61 (registration)
    In the main server setup, registerWebhookTools(server) is called to register all webhook-related tools, including 'list_channel_webhooks'.
    registerEmojiTools(server);
    registerWebhookTools(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