Skip to main content
Glama

discord_create_webhook

Create a Discord webhook to automate messages in a specific channel by providing a channel ID and webhook name using the MCP-Discord server.

Instructions

Creates a new webhook for a Discord channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
avatarNo
channelIdYes
nameYes
reasonNo

Implementation Reference

  • The primary handler function implementing the discord_create_webhook tool. It validates input with Zod, fetches the Discord channel, verifies webhook support, creates the webhook using discord.js, and returns the webhook ID and token on success or appropriate error.
    export async function createWebhookHandler( args: unknown, context: ToolContext ): Promise<ToolResponse> { const { channelId, name, avatar, reason } = CreateWebhookSchema.parse(args); try { if (!context.client.isReady()) { return { content: [{ type: "text", text: "Discord client not logged in." }], isError: true }; } const channel = await context.client.channels.fetch(channelId); if (!channel || !channel.isTextBased()) { return { content: [{ type: "text", text: `Cannot find text channel with ID: ${channelId}` }], isError: true }; } // Check if the channel supports webhooks if (!('createWebhook' in channel)) { return { content: [{ type: "text", text: `Channel type does not support webhooks: ${channelId}` }], isError: true }; } // Create the webhook const webhook = await channel.createWebhook({ name: name, avatar: avatar, reason: reason }); return { content: [{ type: "text", text: `Successfully created webhook with ID: ${webhook.id} and token: ${webhook.token}` }] }; } catch (error) { return handleDiscordError(error); } }
  • src/server.ts:163-166 (registration)
    Tool dispatch/registration in the MCP server request handler switch statement, calling the createWebhookHandler with parsed arguments and tool context.
    case "discord_create_webhook": this.logClientState("before discord_create_webhook handler"); toolResponse = await createWebhookHandler(args, this.toolContext); return toolResponse;
  • MCP tool metadata including name, description, and JSON schema for input validation, used in listTools response.
    { name: "discord_create_webhook", description: "Creates a new webhook for a Discord channel", inputSchema: { type: "object", properties: { channelId: { type: "string" }, name: { type: "string" }, avatar: { type: "string" }, reason: { type: "string" } }, required: ["channelId", "name"] } },
  • Zod schema for input validation used within the handler to parse and type-check arguments.
    export const CreateWebhookSchema = z.object({ channelId: z.string(), name: z.string(), avatar: z.string().optional(), reason: z.string().optional() });

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/barryyip0625/mcp-discord'

If you have feedback or need assistance with the MCP directory API, please join our Discord server