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

195
Visualizações
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 à 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