How can I pull which invite the user used to join the discord

code invite
6 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Joãozinho
Joãozinho10mo ago
const guild = member.guild;
const invites = await guild.invites.fetch();

const usedInvite = invites.find(invite => {
const before = member.client.invites.get(invite.code);
return (!before || before.uses < invite.uses);
});


if (usedInvite) {
console.log(`Membro ${member.user.tag} entrou pelo convite ${usedInvite.code} criado por ${usedInvite.inviter.tag}`);
member.client.invites.set(usedInvite.code, usedInvite);
}
const guild = member.guild;
const invites = await guild.invites.fetch();

const usedInvite = invites.find(invite => {
const before = member.client.invites.get(invite.code);
return (!before || before.uses < invite.uses);
});


if (usedInvite) {
console.log(`Membro ${member.user.tag} entrou pelo convite ${usedInvite.code} criado por ${usedInvite.inviter.tag}`);
member.client.invites.set(usedInvite.code, usedInvite);
}
I tried to do it like this, but it's never pulling code right, do you know how I can do it?
mattblin
mattblin10mo ago
avoid using cache when retrieving your invites
const invites = await guild.invites.fetch({ cache: false });
const invites = await guild.invites.fetch({ cache: false });
Squid
Squid10mo ago
The cache option is for whether the fetched invites should replace the old cached invites, being true by default You're confusing it for the force option which is not read when fetching multiple invites using this method
mattblin
mattblin10mo ago
Yep you're right. Wanted to use force, and messed with cache. Strangely it fixed the exact same problem though 🤔 (Not the exact same code btw) (just in case someone got the same issue : checked this morning, force option failed , option cache: false works in my case coz'
const oldInvites = customVarInvites; //CustomVarInvites was filled with a previous guild.invites.fetch();
customVarInvites = await guild.invites.fetch();
/**for loop on customVarInvites with 'uses' comparison*//
const oldInvites = customVarInvites; //CustomVarInvites was filled with a previous guild.invites.fetch();
customVarInvites = await guild.invites.fetch();
/**for loop on customVarInvites with 'uses' comparison*//
debugging this : *oldInvites *entries are the SAME as *customVarInvites * after fetching. Javascript not my thing so i didn't dig further, but from C/C++ PoV it's like both collection contains ref on cached data So putting cache: false does not affect oldInvites stored values and the loop can make a valid comparison)