Invites
Create and list channel invites, plus guild vanity URLs.
Invites are created on a channel and can be listed for that channel or the whole guild.
Create an invite
createInvite is on guild channels. Narrow with channel.isGuild() when you have message.channel or client.channels.get().
const channel = message.channel;
if (!channel?.isGuild()) return;
const invite = await channel.createInvite({
maxUses: 1,
maxAge: 3600, // seconds; 0 = never expires
});
await message.reply(`Invite: ${invite.url ?? invite.code}`);Options are camelCase (maxUses, maxAge, unique, temporary).
List invites
const channelInvites = await channel.fetchInvites();
const guildInvites = await guild.fetchInvites();
for (const invite of guildInvites) {
console.log(invite.code, invite.uses, invite.maxUses);
}invite.guildSnapshot / invite.channelSnapshot are camelCase metadata, not live structures. Use invite.resolveGuild() / invite.resolveChannel() when you need the cached guild or channel. Discriminate with invite.isGuild() / invite.isGroupDM().
Deleted invites show up via Events.InviteDelete with a camelCase payload (code, guildId, channelId).
Vanity URL
If the guild has a vanity invite:
const vanity = await guild.fetchVanityURL();
console.log(vanity.code, vanity.uses);
await guild.editVanityURL('my-guild');
await guild.editVanityURL(null); // clearRequires Manage Guild. There is no bot API to accept an invite or join a guild.
Tips
- Creating invites needs Create Instant Invite (or Manage Channels, depending on server settings).
- Prefer
channel.createInvitewhen you already have a guild channel (channel.isGuild()). - How people find the server listing: Server Discovery (apply, do not join).
See Channels.