Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda