diff --git a/voice.go b/voice.go index 04fa8ec..87e84b1 100644 --- a/voice.go +++ b/voice.go @@ -360,6 +360,25 @@ func (v *VoiceConnection) wsListen(wsConn *websocket.Conn, close <-chan struct{} v.wsConn = nil v.Unlock() + // Wait for VOICE_SERVER_UPDATE. + // When the bot is moved by the user to another voice channel, + // VOICE_SERVER_UPDATE is received after the code 4014. + for i := 0; i < 5; i++ { // TODO: temp, wait for VoiceServerUpdate. + <-time.After(1 * time.Second) + + v.RLock() + reconnected := v.wsConn != nil + v.RUnlock() + if !reconnected { + continue + } + v.log(LogInformational, "successfully reconnected after 4014 manual disconnection") + return + } + + // When VOICE_SERVER_UPDATE is not received, disconnect as usual. + v.log(LogInformational, "disconnect due to 4014 manual disconnection") + v.session.Lock() delete(v.session.VoiceConnections, v.GuildID) v.session.Unlock()