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

168
Vistas
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
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