Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
Invite logging DiscordJS v13 TypeError: Cannot read property 'inviter' of undefined

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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)
        }
    }) 
})

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!