Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!