Lev
Lev
DIdiscord.js - Imagine ❄
Created by Lev on 1/20/2025 in #djs-questions
Confused About Discord Invites: Are They Always Linked to the Original Creator?
I’m trying to understand how Discord invite links work ? Specifically: - Is each generated invite code always linked to the user who originally created it? - Does users can generate the same link ? - Can a code be shared around by multiple people, and does Discord still store the first user who made it? For example in this snippet, why does the code look for uses differences
client.on("guildMemberAdd", async (member) => {
// To compare, we need to load the current invite list.
const newInvites = await member.guild.invites.fetch()
// This is the *existing* invites for the guild.
const oldInvites = invites.get(member.guild.id);
// Look through the invites, find the one for which the uses went up.
const invite = newInvites.find(i => i.uses > oldInvites.get(i.code));
// This is just to simplify the message being sent below (inviter doesn't have a tag property)
const inviter = await client.users.fetch(invite.inviter.id);
// Get the log channel (change to your liking)
const logChannel = member.guild.channels.cache.find(channel => channel.name === "join-logs");
// A real basic message with the information we need.
inviter
? logChannel.send(`${member.user.tag} joined using invite code ${invite.code} from ${inviter.tag}. Invite was used ${invite.uses} times since its creation.`)
: logChannel.send(`${member.user.tag} joined but I couldn't find through which invite.`);
});
client.on("guildMemberAdd", async (member) => {
// To compare, we need to load the current invite list.
const newInvites = await member.guild.invites.fetch()
// This is the *existing* invites for the guild.
const oldInvites = invites.get(member.guild.id);
// Look through the invites, find the one for which the uses went up.
const invite = newInvites.find(i => i.uses > oldInvites.get(i.code));
// This is just to simplify the message being sent below (inviter doesn't have a tag property)
const inviter = await client.users.fetch(invite.inviter.id);
// Get the log channel (change to your liking)
const logChannel = member.guild.channels.cache.find(channel => channel.name === "join-logs");
// A real basic message with the information we need.
inviter
? logChannel.send(`${member.user.tag} joined using invite code ${invite.code} from ${inviter.tag}. Invite was used ${invite.uses} times since its creation.`)
: logChannel.send(`${member.user.tag} joined but I couldn't find through which invite.`);
});
Tracking Used Invited
6 replies