Code
const id = "815280236974964817"
client.on("ready", async () => {
client.guilds.cache.get(id).invites.fetch().then(inv => {
newInv = inv
})
})
client.on("guildMemberAdd", async member =>{
if(member.guild.id !== id) return;
member.guild.invites.fetch().then(gInvites =>{
const invite = gInvites.find((inv) => newInv.get(inv.code).uses < inv.uses)
console.log(invite.inviter.tag)
})
})
Error
^
TypeError: Cannot read property 'inviter' of undefined
This worked fine in discord.js v12 I've the required intents enabled as well
This error is telling you that invite is undefined.
The find function returns undefined when it can't find an element in the array that matches your testing function.
You need to handle this case by doing something like this:
client.on("guildMemberAdd", async member =>{
if(member.guild.id !== id) return;
member.guild.invites.fetch().then(gInvites =>{
const invite = gInvites.find((inv) => newInv.get(inv.code).uses < inv.uses)
if (!invite) {
// invite does not exist
return;
} else {
// an invite matches the testing function
console.log(invite.inviter.tag)
}
})
})