list_channel_webhooks
Retrieve all webhooks configured in a specific Discord channel. Use this tool to manage automated messaging and integrations by identifying existing webhook connections.
Instructions
List all webhooks in a channel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| channelId | Yes | The ID of the channel |
Implementation Reference
- src/tools/webhook-tools.ts:27-60 (handler)The main execution handler for the list_channel_webhooks tool. Fetches the Discord guild and channel, validates channel type, retrieves webhooks, formats their data (redacting tokens), handles errors via withErrorHandling, 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) }] }; }
- src/tools/webhook-tools.ts:23-26 (schema)Zod schema defining input parameters: guildId (string) and channelId (string) for the tool.{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), },
- src/tools/webhook-tools.ts:20-61 (registration)Direct registration of the list_channel_webhooks tool using server.tool() within the registerWebhookTools 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) }] }; } );
- src/tools/webhook-tools.ts:9-16 (helper)Type guard helper function used in the handler to validate if the channel supports webhooks (GuildText, GuildAnnouncement, GuildVoice, GuildForum).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-60 (registration)Top-level call to register all webhook tools (including list_channel_webhooks) in the main MCP server setup.registerWebhookTools(server);