Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 9effc92

Browse files
Fix the problem of reconnecting when moved to another VC (bwmarrin#1271)
* Fix disconnection when moved to another VC * Update voice.go Co-authored-by: Fedor Lapshin <[email protected]> * Update voice.go Co-authored-by: Fedor Lapshin <[email protected]> * Update voice.go Co-authored-by: Fedor Lapshin <[email protected]> * feat: add VoiceServerUpdate todo Co-authored-by: Fedor Lapshin <[email protected]>
1 parent b818826 commit 9effc92

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

voice.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,25 @@ func (v *VoiceConnection) wsListen(wsConn *websocket.Conn, close <-chan struct{}
360360
v.wsConn = nil
361361
v.Unlock()
362362

363+
// Wait for VOICE_SERVER_UPDATE.
364+
// When the bot is moved by the user to another voice channel,
365+
// VOICE_SERVER_UPDATE is received after the code 4014.
366+
for i := 0; i < 5; i++ { // TODO: temp, wait for VoiceServerUpdate.
367+
<-time.After(1 * time.Second)
368+
369+
v.RLock()
370+
reconnected := v.wsConn != nil
371+
v.RUnlock()
372+
if !reconnected {
373+
continue
374+
}
375+
v.log(LogInformational, "successfully reconnected after 4014 manual disconnection")
376+
return
377+
}
378+
379+
// When VOICE_SERVER_UPDATE is not received, disconnect as usual.
380+
v.log(LogInformational, "disconnect due to 4014 manual disconnection")
381+
363382
v.session.Lock()
364383
delete(v.session.VoiceConnections, v.GuildID)
365384
v.session.Unlock()

0 commit comments

Comments
 (0)