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
| 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 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) }] }; }
- src/tools/invite-tools.ts:91-99 (schema)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'), },
- src/tools/invite-tools.ts:88-140 (registration)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);
- src/tools/invite-tools.ts:7-7 (helper)Type definition for channels that support invites, used in the create_invite handler.type InvitableChannel = TextChannel | VoiceChannel | StageChannel | NewsChannel;