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

81
Visualizações
I have this code below i want the counter to reset to 0 after the message is sent
let msgCount = 0; // This being outside the event in index.js

// Event here
client.on("messageCreate", async(message)=>{
    if (message.author.bot) return;
    if (message.channel.id === "id here") {
        msgCount = msgCount + 1;
    }
    if (msgCount === 100) {
        const channel = await client.channels.cache.get("id here")
       channel.send("hi")  
    }    
})

But it only sends the message 1 time and doesn't reset the counter to 0 so it only works 1 time how can I fix it?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could just wait for the message to be sent and then set the msgCountvariable to 0.

let msgCount = 0; // This being outside the event in index.js

// Event here
client.on("messageCreate", async (message) => {
    if (message.author.bot) return;
    if (message.channel.id === "id here") {
        msgCount = msgCount + 1;
    }
    if (msgCount === 100) {
        const channel = await client.channels.cache.get("id here")
        await channel.send("hi")
        msgCount = 0
    }    
})
about 4 years ago · Juan Pablo Isaza Relatório

0

You never reset it... you only increment it. Just use this and it will change it back to 0 when the message is sent

if (msgCount === 100) {
    const channel = await client.channels.cache.get("id here")
    channel.send("hi")
    msgCount = 0
}
about 4 years ago · Juan Pablo Isaza Relatório
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