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

122
Visualizações
undefined (reading 'videos')

Trying to get a discord bot to join a channel and play a link but I get this error

TypeError: Cannot read properties of undefined (reading 'videos')

my command handler is fine with other simpler commands

    const videoFinder = async (query) => {
        const videoResult = await ytSearch(query);

        return (videoResult.videos.length > 1) ? videoResult.videos[0] : null;
    }

This is the line that gets me the error

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You may try something like this :

const videoFinder = async (query) => {
        const videoResult = await ytSearch(query);

        return (videoResult?.videos?.length > 1) ? videoResult?.videos[0] : null;
    }

The ? will check the object before exists. If not, it returns undefined and in your case, null, because undefined.videos doesn't exist.

Alternatively :

const videoFinder = async (query) => {
        const videoResult = await ytSearch(query);
        if (!videoResult || !videoResult.videos) return null
        return videoResult.videos[0]
    }
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