diff --git a/package.json b/package.json index 45010cb..58dc38f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-player-play-dl", - "version": "5.3.13", + "version": "5.3.14", "description": "Complete framework to facilitate music commands using discord.js and play-dl", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/VoiceInterface/StreamDispatcher.ts b/src/VoiceInterface/StreamDispatcher.ts index d6575e0..37af32c 100644 --- a/src/VoiceInterface/StreamDispatcher.ts +++ b/src/VoiceInterface/StreamDispatcher.ts @@ -9,7 +9,8 @@ import { StreamType, VoiceConnection, VoiceConnectionStatus, - VoiceConnectionDisconnectReason + VoiceConnectionDisconnectReason, + VoiceConnectionState } from "@discordjs/voice"; import { StageChannel, VoiceChannel } from "discord.js"; import { Duplex, Readable } from "stream"; @@ -68,7 +69,20 @@ class StreamDispatcher extends EventEmitter { */ this.paused = false; - this.voiceConnection.on("stateChange", async (_, newState) => { + this.voiceConnection.on("stateChange", async (oldState, newState) => { + // oh no, fix no work + const oldNetworking = Reflect.get(oldState, "networking"); + const newNetworking = Reflect.get(newState, "networking"); + + const networkStateChangeHandler = (_: VoiceConnectionState, newNetworkState: VoiceConnectionState) => { + const newUdp = Reflect.get(newNetworkState, "udp"); + clearInterval(newUdp?.keepAliveInterval); + }; + + oldNetworking?.off("stateChange", networkStateChangeHandler); + newNetworking?.on("stateChange", networkStateChangeHandler); + // temp fix end + if (newState.status === VoiceConnectionStatus.Disconnected) { if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) { try {