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

276
Visualizações
DiscordJS Cannot read properties of null (reading 'id')

I am attempting to log when someone joins vc and moves vc, the moving vc logging works well but when joining a vc it gives the error TypeError: Cannot read properties of null (reading 'id')

module.exports = async (client, oldState, newState) => {
        if (oldState.channel && newState.channel && oldState.channel.id !== newState.channel.id) {
            const embed = new Discord.MessageEmbed()
                .setAuthor({ name: newState.member.user.tag, iconURL: newState.member.user.displayAvatarURL({ dynamic: true }) })
                .setTimestamp()
                .setColor(config.colour)
                .setFooter({ text: newState.guild.name, iconURL: newState.guild.iconURL({ dynamic: true }) })
                .setDescription(`**${newState.member} moved from \`${oldState.channel.name}\` to \`${newState.channel.name}\`**`)
            return logChannel.send({ embeds: [embed] })
        }
        if (!oldState.channel.id && newState.channel.id) {
            const embed = new Discord.MessageEmbed()
                .setAuthor({ name: newState.member.user.tag, iconURL: newState.member.user.displayAvatarURL({ dynamic: true }) })
                .setTimestamp()
                .setColor(config.colour)
                .setFooter({ text: newState.guild.name, iconURL: newState.guild.iconURL({ dynamic: true }) })
                .setDescription(`**🔊 ${newState.member} has joined \`${newState.channel.name}\` channel.**`)
            return logChannel.send({ embeds: [embed] })
        }
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When the first time joining the channel, there's no oldState.channel so bot can't fetch id of a channel which is not exist. You can edit your statements like;

if (oldState.channel && newState.channel && oldState.channel.id !== newState.channel.id)

to

if(oldState.channel && newState.channel){
if(oldState.channel.id != newState.channel.id){
 // rest of code
}
}

maybe you can make more clean but this is how it works.

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