Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda