File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -255,9 +255,14 @@ func (g *gatewayImpl) heartbeat() {
255
255
func (g * gatewayImpl ) sendHeartbeat () {
256
256
g .config .Logger .Debug ("sending heartbeat" )
257
257
258
+ sequence := - 1
259
+ if g .config .LastSequenceReceived != nil {
260
+ sequence = * g .config .LastSequenceReceived
261
+ }
262
+
258
263
ctx , cancel := context .WithTimeout (context .Background (), g .heartbeatInterval )
259
264
defer cancel ()
260
- if err := g .Send (ctx , OpcodeHeartbeat , MessageDataHeartbeat (* g . config . LastSequenceReceived )); err != nil {
265
+ if err := g .Send (ctx , OpcodeHeartbeat , MessageDataHeartbeat (sequence )); err != nil {
261
266
if errors .Is (err , discord .ErrShardNotConnected ) || errors .Is (err , syscall .EPIPE ) {
262
267
return
263
268
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package gateway
2
2
3
3
import (
4
4
"fmt"
5
+ "strconv"
5
6
6
7
"github.com/disgoorg/json"
7
8
"github.com/disgoorg/snowflake/v2"
@@ -496,6 +497,13 @@ func (MessageDataUnknown) messageData() {}
496
497
// MessageDataHeartbeat is used to ensure the websocket connection remains open, and disconnect if not.
497
498
type MessageDataHeartbeat int
498
499
500
+ func (m MessageDataHeartbeat ) MarshalJSON () ([]byte , error ) {
501
+ if m == - 1 {
502
+ return json .NullBytes , nil
503
+ }
504
+ return []byte (strconv .Itoa (int (m ))), nil
505
+ }
506
+
499
507
func (MessageDataHeartbeat ) messageData () {}
500
508
501
509
// MessageDataIdentify is the data used in IdentifyCommandData
You can’t perform that action at this time.
0 commit comments