From 9ca484e50c7672640730df5f1b18eff8f97724c3 Mon Sep 17 00:00:00 2001 From: fakelag <35497506+fakelag@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:47:58 +0200 Subject: [PATCH] Disconnect old audio session before creating new --- discordplayer/discordplayer_test.go | 2 ++ discordplayer/voiceworker.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/discordplayer/discordplayer_test.go b/discordplayer/discordplayer_test.go index 885ee76..1f2c50c 100644 --- a/discordplayer/discordplayer_test.go +++ b/discordplayer/discordplayer_test.go @@ -1008,6 +1008,7 @@ var _ = Describe("Discord Player", func() { gomock.InOrder( playerContext.mockVoiceConnection.EXPECT().Speaking(false), playerContext.mockVoiceConnection.EXPECT().IsReady().Return(false), + playerContext.mockVoiceConnection.EXPECT().Disconnect(), playerContext.mockDiscordSession.EXPECT(). ChannelVoiceJoin(playerContext.guildID, playerContext.channelID, false, false). Return(playerContext.mockVoiceConnection, nil), @@ -1066,6 +1067,7 @@ var _ = Describe("Discord Player", func() { playerContext.mockVoiceConnection.EXPECT().Speaking(false), mockDcaStreamingSession.EXPECT().PlaybackPosition().Return(10*time.Second).MinTimes(1), playerContext.mockVoiceConnection.EXPECT().IsReady().Return(false), + playerContext.mockVoiceConnection.EXPECT().Disconnect(), playerContext.mockDiscordSession.EXPECT(). ChannelVoiceJoin(playerContext.guildID, playerContext.channelID, false, false). Return(playerContext.mockVoiceConnection, nil), diff --git a/discordplayer/voiceworker.go b/discordplayer/voiceworker.go index 127e959..a782c80 100644 --- a/discordplayer/voiceworker.go +++ b/discordplayer/voiceworker.go @@ -266,6 +266,10 @@ func (dms *DiscordMusicSession) checkDiscordVoiceConnection() error { return nil } + if dms.voiceConnection != nil { + _ = dms.voiceConnection.Disconnect() + } + dms.mutex.RLock() voiceChannelID := dms.voiceChannelID dms.mutex.RUnlock()