Skip to main content
Glama
scarecr0w12

discord-mcp

create_invite

Generate Discord server invites for channels with customizable expiration, usage limits, and membership settings to manage access control.

Instructions

Create an invite for a channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the channel
maxAgeNoMax age in seconds (0 = never, default 86400)
maxUsesNoMax uses (0 = unlimited, default 0)
temporaryNoGrant temporary membership (default false)
uniqueNoCreate a unique invite (default false)
reasonNoReason for creating

Implementation Reference

  • The handler function implementing the core logic of the 'create_invite' tool. It fetches the guild and channel, validates the channel type, creates the invite using Discord.js API, and returns the invite details or error.
    async ({ guildId, channelId, maxAge, maxUses, temporary, unique, 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 (!channel) throw new Error('Channel not found');
    
        // Check if channel type supports invites
        if (channel.type === ChannelType.GuildCategory) {
          throw new Error('Cannot create invite for category channels');
        }
    
        const invitableChannel = channel as InvitableChannel;
        const invite = await invitableChannel.createInvite({
          maxAge,
          maxUses,
          temporary,
          unique,
          reason,
        });
    
        return {
          code: invite.code,
          url: invite.url,
          channelId: invite.channelId,
          maxAge: invite.maxAge,
          maxUses: invite.maxUses,
          temporary: invite.temporary,
          expiresAt: invite.expiresAt?.toISOString(),
          message: 'Invite 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 schema defining the input parameters for the 'create_invite' tool, including guildId, channelId, and optional invite options.
    {
      guildId: z.string().describe('The ID of the server (guild)'),
      channelId: z.string().describe('The ID of the channel'),
      maxAge: z.number().optional().describe('Max age in seconds (0 = never, default 86400)'),
      maxUses: z.number().optional().describe('Max uses (0 = unlimited, default 0)'),
      temporary: z.boolean().optional().describe('Grant temporary membership (default false)'),
      unique: z.boolean().optional().describe('Create a unique invite (default false)'),
      reason: z.string().optional().describe('Reason for creating'),
    },
  • The registration of the 'create_invite' tool with the MCP server using server.tool(), including name, description, input schema, and handler function.
    server.tool(
      'create_invite',
      'Create an invite for a channel',
      {
        guildId: z.string().describe('The ID of the server (guild)'),
        channelId: z.string().describe('The ID of the channel'),
        maxAge: z.number().optional().describe('Max age in seconds (0 = never, default 86400)'),
        maxUses: z.number().optional().describe('Max uses (0 = unlimited, default 0)'),
        temporary: z.boolean().optional().describe('Grant temporary membership (default false)'),
        unique: z.boolean().optional().describe('Create a unique invite (default false)'),
        reason: z.string().optional().describe('Reason for creating'),
      },
      async ({ guildId, channelId, maxAge, maxUses, temporary, unique, 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 (!channel) throw new Error('Channel not found');
    
          // Check if channel type supports invites
          if (channel.type === ChannelType.GuildCategory) {
            throw new Error('Cannot create invite for category channels');
          }
    
          const invitableChannel = channel as InvitableChannel;
          const invite = await invitableChannel.createInvite({
            maxAge,
            maxUses,
            temporary,
            unique,
            reason,
          });
    
          return {
            code: invite.code,
            url: invite.url,
            channelId: invite.channelId,
            maxAge: invite.maxAge,
            maxUses: invite.maxUses,
            temporary: invite.temporary,
            expiresAt: invite.expiresAt?.toISOString(),
            message: 'Invite 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) }] };
      }
    );
  • src/index.ts:62-62 (registration)
    Call to registerInviteTools which includes the 'create_invite' tool among other invite tools.
    registerInviteTools(server);
  • Type definition for channels that support invites, used in the create_invite handler.
    type InvitableChannel = TextChannel | VoiceChannel | StageChannel | NewsChannel;

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