Stop voice re-connection on manual disconnection
This commit is contained in:
parent
69edfdf4ac
commit
a7305dd7b7
1 changed files with 19 additions and 0 deletions
19
voice.go
19
voice.go
|
@ -346,6 +346,25 @@ func (v *VoiceConnection) wsListen(wsConn *websocket.Conn, close <-chan struct{}
|
||||||
for {
|
for {
|
||||||
_, message, err := v.wsConn.ReadMessage()
|
_, message, err := v.wsConn.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// 4014 indicates a manual disconnection by someone in the guild;
|
||||||
|
// we shouldn't reconnect.
|
||||||
|
if websocket.IsCloseError(err, 4014) {
|
||||||
|
v.log(LogInformational, "received 4014 manual disconnection")
|
||||||
|
|
||||||
|
// Abandon the voice WS connection
|
||||||
|
v.Lock()
|
||||||
|
v.wsConn = nil
|
||||||
|
v.Unlock()
|
||||||
|
|
||||||
|
v.session.Lock()
|
||||||
|
delete(v.session.VoiceConnections, v.GuildID)
|
||||||
|
v.session.Unlock()
|
||||||
|
|
||||||
|
v.Close()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Detect if we have been closed manually. If a Close() has already
|
// Detect if we have been closed manually. If a Close() has already
|
||||||
// happened, the websocket we are listening on will be different to the
|
// happened, the websocket we are listening on will be different to the
|
||||||
// current session.
|
// current session.
|
||||||
|
|
Loading…
Reference in a new issue