112
rated 0 times
[
114]
[
2]
/ answers: 1 / hits: 16990
/ 7 Years ago, tue, july 11, 2017, 12:00:00
I am coding a multipurpose Discord bot to replace some of the more minor ones, and I am looking for a piece of code for a feature that recognizes repeated messages or messages sent in a very short time period (let's say 5000ms).
Here is what could be used to implement this idea.
client.on(message, (message) => {
//let's use something like a spam variable for 10 or more messages sent within 5000ms
if(message.content === spam) {
message.reply(Warning: Spamming in this channel is forbidden.);
console.log(message.author.username + ( + message.author.id + ) has sent 10 messages or more in 5 seconds in + message.channel.name + .);
}
});
For reference, I also made a feature that deletes messages, using a ~delete [n] command. It looks like this:
//this will only delete one message in the channel, the most recent one.
message.delete(1000);
//1000 represents the timeout duration. it will only delete one message, regardless of the value.
//we can delete multiple messages with this, but note it has to come before the reply message.
message.channel.bulkDelete(11);
I was thinking of somehow combining the delete command with recognizing spam messages. If you have any ideas, that would be perfect.
More From » command