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
| 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 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) }] }; }
- src/tools/webhook-tools.ts:20-61 (registration)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) }] }; } );
- src/tools/webhook-tools.ts:24-26 (schema)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'), },
- src/tools/webhook-tools.ts:9-16 (helper)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);