Is there a way to stop this ? If it checks the database for words for example (ARE,DOING) If a message has been send like this: (how are you doing) it triggers 2x delete message and 2x my message.
this is how i have it setup:
Database12.find(guild, async(err, data) => {
splittedMsgs.map((content) =>{
if(message.content.bot) return
if (data.Words.includes(content.toLowerCase())){
//deletes the bad message
message.delete()
// reply a message when a bad word has been detected
message.reply(replies[random])
.then(msg => {
let time = "5s";
setTimeout(function () {
// if (message.author.bot) return;
//deletes the detected message
msg.delete();
}, ms(time));
})
.catch(console.log("error"));
};
});
});
I did try a lot, but i don't find a way to stop it looping when 2 words are detected at the same time in one message.
regards
You could consider using Array.some. That way, it will stop looping through the array, if a given element resolves to true:
Database12.find(guild, async (err, data) => {
if (message.content.bot) return
if (splittedMsgs.some((content) => data.Words.includes(content.toLowerCase()))) {
//deletes the bad message
message.delete()
// reply a message when a bad word has been detected
message.reply(replies[random])
.then(msg => {
let time = "5s";
setTimeout(function () {
// if (message.author.bot) return;
//deletes the detected message
msg.delete();
}, ms(time));
})
.catch(console.log("error"));
}
});
Besides, you should always use the correct array method. You used Array.map, which is typically used to create a new array whilst changing each element of the given array see here.
If you just want to iterate over each element (without changing it), you should use Array.forEach instead see here.
If you are interested, here is an article with a short explanation and examples regarding some array methods.