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

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