Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the problem of reconnecting when moved to another VC #1271

Merged
merged 5 commits into from
Dec 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions voice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down