Skip to main content
Glama

create_invite

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

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 main handler function that executes the tool logic: fetches guild and channel, validates, creates invite via Discord.js API, handles errors, and formats response.
    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.
    { 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'), },
  • MCP server.tool registration call for 'create_invite', including name, description, input schema, and handler reference.
    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:61-61 (registration)
    Invocation of registerInviteTools which registers the create_invite tool among others.
    registerInviteTools(server);

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