feat(ws): add toggle for voice reconnects on session reconnect (#1350)
* Add flag for voice reconnect on session reconnect * Rename ShouldReconnectVoiceConnOnError toggle as suggested Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * Fix indentaion for discord.go * Change wording in docs --------- Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
This commit is contained in:
parent
af63880a0b
commit
a90485df0c
3 changed files with 28 additions and 23 deletions
|
@ -38,6 +38,7 @@ func New(token string) (s *Session, err error) {
|
|||
StateEnabled: true,
|
||||
Compress: true,
|
||||
ShouldReconnectOnError: true,
|
||||
ShouldReconnectVoiceOnSessionError: true,
|
||||
ShouldRetryOnRateLimit: true,
|
||||
ShardID: 0,
|
||||
ShardCount: 1,
|
||||
|
|
|
@ -42,6 +42,9 @@ type Session struct {
|
|||
// Should the session reconnect the websocket on errors.
|
||||
ShouldReconnectOnError bool
|
||||
|
||||
// Should voice connections reconnect on a session reconnect.
|
||||
ShouldReconnectVoiceOnSessionError bool
|
||||
|
||||
// Should the session retry requests when rate limited.
|
||||
ShouldRetryOnRateLimit bool
|
||||
|
||||
|
|
3
wsapi.go
3
wsapi.go
|
@ -862,6 +862,7 @@ func (s *Session) reconnect() {
|
|||
// However, there seems to be cases where something "weird"
|
||||
// happens. So we're doing this for now just to improve
|
||||
// stability in those edge cases.
|
||||
if s.ShouldReconnectVoiceOnSessionError {
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
for _, v := range s.VoiceConnections {
|
||||
|
@ -872,7 +873,7 @@ func (s *Session) reconnect() {
|
|||
// This is here just to prevent violently spamming the
|
||||
// voice reconnects
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue