fix: cleanup streams on disconnection

This commit is contained in:
2026-01-15 12:50:30 -03:00
parent e1363de9df
commit fd75f692d5
+12 -1
View File
@@ -3,7 +3,8 @@ import {
createAudioPlayer,
createAudioResource,
StreamType,
VoiceConnection
VoiceConnection,
VoiceConnectionStatus
} from '@discordjs/voice';
import { AudioMixer } from 'node-audio-mixer';
import { PassThrough, Readable } from 'stream';
@@ -171,6 +172,16 @@ export class AudioStreamManager {
stream = new MixedStream();
this.streams.set(conn, stream);
conn.subscribe(stream.player);
conn.on('stateChange', (_, newState) => {
if (
newState.status === VoiceConnectionStatus.Disconnected ||
newState.status === VoiceConnectionStatus.Destroyed
) {
this.destroyStream(conn);
}
});
return stream;
}