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

156
Views
Discord.js music bot - stream issues

For some reason, my code suddenly doesn't work as intended. It worked just a few weeks ago, yet now it refuses to work. I forgot how I tampered with it, but I'm pretty sure it isn't by much. After joining a voice channel, my bot attempts to create an AudioResource via the stream provided by ytdl() function from ytdl-core. After that I played the resource in an AudioPlayer and subscribed to it.

...The problem is that while the bot lights up in green(indicating it is speaking), there is no sound. It continues to stay there for what I assume to be the duration of the stream I passed in before leaving. I have reason to believe that there's a problem in this part:

const songQueue = queue.get(message.guild.id);
let songPlayer = Voice.createAudioPlayer();

const waterMark = song.duration.seconds * 16384;
let source = await ytdl(song.url, {
  filter: 'audioonly',
  type: 'opus',
  highWaterMark: waterMark,
  requestOptions: {
    headers: {
      cookie: process.env.COOKIE
    }
  }
})

let stream = Voice.createAudioResource(source, {
  inputType: Voice.StreamType.Arbitrary
})

try {
  await songPlayer.play(stream);
} catch(err) {
  console.log(err);
  console.log(songPlayer);
}

When I attempted to pipe() the results, it did get written as a file. The problem is that when I play it for a few seconds, it goes right to the end. Which led me to believe there might be an issue with the stream... did I mess up by await-ing or not await-ing some line of code?

I know ytdl stream is PassThrough-- but there seems to be an issue. Is there an alternative, or does the issue lie on discord instead of ytdl?

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!