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?
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
}
})
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
}