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().

javascript
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

javascript
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:

javascript
const vanity = await guild.fetchVanityURL();
console.log(vanity.code, vanity.uses);

await guild.editVanityURL('my-guild');
await guild.editVanityURL(null); // clear

Requires Manage Guild. There is no bot API to accept an invite or join a guild.

Tips

See Channels.

Questions?Join the Fluxer community for help with the SDK.Join Fluxer