'I want bot to send first message only
I'm making a spam command. I want users to enter a message to spam but only the first message should be spam. No other message should be registered if 1 spam is already running. My code -
else if (command === prefix + "spam" && args[0] !== undefined) {
message.reply("Quick tip: Use `stopspam` command to stop this")
spamInterval = setInterval(() => {
message.channel.send(`${args.slice(0).join(" ")}`);
}, 1500);
}
Solution 1:[1]
Define outside an status variable
let spamrunning=0
Then add the condition of that status variable, and the change of it.
else if (command === prefix + "spam" && args[0] !== undefined && spamrunning==0) {
message.reply("Quick tip: Use `stopspam` command to stop this")
spamrunning=1
spamInterval = setInterval(() => {
message.channel.send(`${args.slice(0).join(" ")}`);
}, 1500);
}
and change status again when you clear the interval
else if (command === prefix + "stopspam") {
...
spamrunning=0
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | 19mike95 |
