Skip to main content
Glama

discord_create_webhook

Create a Discord webhook to automate messages in a specific channel. Provide channel ID and webhook name to set up automated notifications or integrations.

Instructions

Creates a new webhook for a Discord channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelIdYes
nameYes
avatarNo
reasonNo

Implementation Reference

  • The core handler function that implements the discord_create_webhook tool. It validates input using CreateWebhookSchema, fetches the channel, checks permissions, creates the webhook using discord.js channel.createWebhook, and returns success/error response.
    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?.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,
          avatar,
          reason,
        });
    
        return {
          content: [
            {
              type: 'text',
              text: `Successfully created webhook with ID: ${webhook.id} and token: ${webhook.token}`,
            },
          ],
        };
      } catch (error) {
        return handleDiscordError(error);
      }
    }
  • Zod schema for validating input parameters of the discord_create_webhook tool: channelId (required), name (required), avatar (optional), reason (optional). Used in the handler for parsing args.
    export const CreateWebhookSchema = z.object({
      channelId: z.string(),
      name: z.string(),
      avatar: z.string().optional(),
      reason: z.string().optional(),
    });
  • Tool registration entry in the toolList array, defining name, description, and inputSchema. This is returned by list_tools endpoint.
    {
      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'],
      },
    },
  • src/server.ts:186-189 (registration)
    Switch case in DiscordMCPServer that dispatches 'discord_create_webhook' calls to the createWebhookHandler function.
    case 'discord_create_webhook':
      this.logClientState('before discord_create_webhook handler');
      toolResponse = await createWebhookHandler(args, this.toolContext);
      return toolResponse;
  • Re-export of the webhook handlers, including createWebhookHandler, allowing centralized imports from './tools/tools.js' used in server.ts and transport.ts.
      createWebhookHandler,
      deleteWebhookHandler,
      editWebhookHandler,
      sendWebhookMessageHandler,
    } from './webhooks.js';

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

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