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()