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
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| channelId | Yes | The ID of the channel | |
| maxAge | No | Max age in seconds (0 = never, default 86400) | |
| maxUses | No | Max uses (0 = unlimited, default 0) | |
| temporary | No | Grant temporary membership (default false) | |
| unique | No | Create a unique invite (default false) | |
| reason | No | Reason for creating |
Implementation Reference
- src/tools/invite-tools.ts:100-139 (handler)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) }] }; }
- src/tools/invite-tools.ts:91-99 (schema)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'), },
- src/tools/invite-tools.ts:88-140 (registration)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);