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

80
Views
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 answers
Answer question

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 Report

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 Report
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!