How to handle Audio Receive Stream Pipeline on Connection Destroy (bot disconnected)

This is my code inside my receiver speaking on start event:
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 800
}
});

const decoder = new opus.Decoder({ frameSize: 960, channels: 1, rate: 8000 });
const rawAudio = pipeline(opusStream, decoder, () => null);
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 800
}
});

const decoder = new opus.Decoder({ frameSize: 960, channels: 1, rate: 8000 });
const rawAudio = pipeline(opusStream, decoder, () => null);
The problem is, I believe that 'rawAudio' is causing the following error when the connection is destroyed (bot is disconnected) and a user is speaking at the same time because the stream is not dealt with properly:
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
How can I resolve this and handle the rawAudio pipeline correctly?
3 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
dzlandis
dzlandisOP•2y ago
@discordjs/voice v0.14.0 discord.js v14.7.1 I'll add that the error only appears when using connection.destroy() and does not occur when manually disconnecting the bot from the channel. I'm wondering if this is an unintended bug and if I should report it instead 🤔 Just got this error again after a while so I'm gonna try and resurface this.
dzlandis
dzlandisOP•2y ago
Just remembered I opened an issue here: https://github.com/discordjs/discord.js/issues/8967 If anyone finds a solution though, that would be awesome!
GitHub
Connection.destroy() causes 'Premature Close' when pipeline is rece...
Which package is this bug report for? voice Issue description Have the bot join a voice channel and start voice receiving While speaking in the voice channel, run connection.destroy() to destroy th...
Want results from more Discord servers?
Add your server