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?