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

178
Visualizações
Why is the "count + counter" variable showing up as undefined?

I am trying to make a bot on Slack to post a message on one channel when a message is received on another channel, and that it only runs once a day. This is my code with the message that I got (with what I have done.) How do I fix this to be right?

const web = new WebClient(process.env.SLACK_TOKEN);
const currentTime = new Date().toTimeString();
let channelId = "C02FHG0K0SY";
let conversationHistory, message, count, stop;
let counter;

async function fetchMessages() {
  const result = await web.conversations.history({
    channel: channelId,
    limit: 11000,
  });

  conversationHistory = result.messages;

  count = conversationHistory.length;
}

setInterval(function () {
  if (counter === null) {
    fetchMessages();
    var count = fetchMessages.count;
    counter === count;
    console.log("Counter has been setup!");
  }

  if (counter === count) {
    fetchMessages();
    if (count > counter) {
      web.chat.postMessage({
        token: process.env.SLACK_TOKEN,
        channel: "C02FB9QHW10",
        text: "Hits have arrived, let's get started with them! Woo-hoo! This is just a test by the way, no hits have actually arrived.",
      });
      stop === true;
      console.log("Hits arrived! Posted.")
    } else {
      console.log(`No new hits! ${count} messages and ${counter} in "counter".`);
    }
  }
}, 5000);

setInterval(function () {
  if (currentTime == "23:59:59 GMT+0000 (Coordinated Universal Time)") {
    if (stop === true) {
      stop === false;
    }
  }
}, 1000);
No new hits! undefined messages and undefined in "counter".
about 4 years ago · Santiago Trujillo
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