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

191
Vistas
Any suggestions on why ytdl wouldn't be downloading my video properly?

I am currently creating a discord bot that will download a YouTube video into video.mp4 and play that video using the established connection, however, I keep getting this unfamiliar error that I am not sure how to interpret. The important section of my code is as follows:

        console.log(video); //YouTube video id ex: 6Fw4B5ALC1o
        const connection2 = joinVoiceChannel({
            channelId: msg.member.voice.channel.id,
            guildId: msg.guild.id,
            adapterCreator: msg.channel.guild.voiceAdapterCreator

        });
        ytdl('https://www.youtube.com/watch?v=' + video).pipe(fs.createWriteStream('video.mp4'))
        console.log("video downloaded");
            
        const player = createAudioPlayer('video.mp4');
        console.log("player created");
        player.play();

The error:

/Users/sam/Desktop/DCordBot/node_modules/@discordjs/voice/dist/index.js:944
    if (resource.ended) {
                 ^

TypeError: Cannot read properties of undefined (reading 'ended')
    at AudioPlayer.play (/Users/sam/Desktop/DCordBot/node_modules/@discordjs/voice/dist/index.js:944:18)
    at Client.<anonymous> (/Users/sam/Desktop/DCordBot/main.js:179:16)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

The size of video.mp4 is consistently 0 bytes, which confuses me, because if I insert the link "http://www....." + "videoID" into the search bar it will bring up the YouTube video that I want. I am not sure why, but it's not downloading the video properly, does anyone have any suggestions or insight as to what the problem might be? Thanks.

about 4 years ago · Juan Pablo Isaza
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