Skip to main content
Glama

create_webhook

Create a Discord webhook in a specified channel to automate message delivery and integrate external services with your server.

Instructions

Create a webhook in a channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the channel
nameYesName for the webhook
avatarNoURL of the avatar image
reasonNoReason for creating

Implementation Reference

  • The handler function that executes the tool: fetches guild and channel, checks if channel supports webhooks, creates the webhook using Discord.js, handles errors with withErrorHandling, and returns JSON response.
    async ({ guildId, channelId, name, avatar, 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 (!isWebhookableChannel(channel)) { throw new Error('Channel does not support webhooks'); } const webhook = await channel.createWebhook({ name, avatar, reason }); return { id: webhook.id, name: webhook.name, channelId: webhook.channelId, token: webhook.token, url: webhook.url, message: 'Webhook created 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 required parameters (guildId, channelId, name) and optional (avatar, reason).
    { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), name: z.string().describe('Name for the webhook'), avatar: z.string().optional().describe('URL of the avatar image'), reason: z.string().optional().describe('Reason for creating'), },
  • The server.tool() call that registers the 'create_webhook' tool with name, description, input schema, and handler function on the MCP server.
    server.tool( 'create_webhook', 'Create a webhook in a channel', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), name: z.string().describe('Name for the webhook'), avatar: z.string().optional().describe('URL of the avatar image'), reason: z.string().optional().describe('Reason for creating'), }, async ({ guildId, channelId, name, avatar, 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 (!isWebhookableChannel(channel)) { throw new Error('Channel does not support webhooks'); } const webhook = await channel.createWebhook({ name, avatar, reason }); return { id: webhook.id, name: webhook.name, channelId: webhook.channelId, token: webhook.token, url: webhook.url, message: 'Webhook created 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 type guard function used in the handler to validate if the channel type supports webhooks.
    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; }

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