Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda