Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Discord Api doesn't send events anymore after first heartbeat sended

I've a problem, when I start my bot, all commands work, but when I send the first heartbeat, Discord Api doesn't send me events anymore. My code:

botToken = token;

    const ws = new WebSocket("wss://gateway.discord.gg/?v=6&encoding=json");

    let interval = 0;
    let session_id;
    let last_seq;
    let payload = {
      op: 2,
      d: {
        token: botToken,
        intents: 32767,
        properties: {
          $os: "linux",
          $browser: "chrome",
          $device: "chrome",
        },
      },
    };

    ws.on("open", function open() {
      ws.send(JSON.stringify(payload));
    });

    ws.on("message", function incoming(data) {
      let response = JSON.parse(data);
      const { t, event, op, d, s } = response;

      last_seq = s;

      switch (op) {
        case 10:
          const { heartbeat_interval } = d;
          interval = heartbeat(heartbeat_interval);
        break;
        case 7:
          ws.send(JSON.stringify({
            op: 6, 
            d: {
              token: botToken,
              session_id: session_id,
              last_seq: s
            } 
          })) 
        break;
      }

      if(t == "READY") {
        session_id = d.session_id;
        console.log("session id: " + session_id)
      }
      let eventName = t + "Callback";
      console.log(t)
      if(callbacks[eventName]) {
        if (typeof callbacks[eventName] == "function") {
          callbacks[eventName](d);
        }
      }
    });

    const heartbeat = (ms) => {
      return setInterval(() => {
        console.log("heartbeat sended")
        ws.send(JSON.stringify({ op: 3, d: last_seq }));
      }, ms);
    };

Console output:

Console output:

As you can see, after "heartbeat sended" I don't receive events anymore. Where is the problem?

Thanks in advance and sorry for bad english!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!