I'm trying to make my discord bot so that it flags in the console whenever certain words are typed by a user. The code works completely fine if the first word contains the words that are set to flag, but if someone put "You are a n****" it would not detect but just "n****" does flag beacuse of this it also has problems flagging when multiple words that should be flagged are said.
client.flags = new Discord.Collection();
const flagFiles = fs.readdirSync('./flag/').filter(file => file.endsWith('.js'));
for(const file of flagFiles){
const flag = require(`./flag/${file}`);
client.flags.set(flag.name, flag);
}
client.on("message", function(message){
console.log("Channel:" + color.blue(message.channel) + " " + "Author:" + color.blue(message.author) + " " + "Message:" + color.blue(message.content))
if (message.author.bot) return;
const flagwords = ["spam","Spam","Nig", "nig", "N19", "n19"];
const args1 = message.content.slice(flagwords).split(/ +/);
const msg = args1.shift().toLowerCase();
if (msg.includes("spam") || msg == "spam" || msg == "spam" || msg.includes("spam")) {
client.flags.get("spam").execute(message, args1);
}
if (msg.includes("nig") || msg == "nig" || msg == "nig" || msg.includes("nig")) {
client.flags.get("nigga").execute(message, args1);
}
if (msg.includes("n19") || msg == "n19" || msg == "n19" || msg.includes("n19")) {
client.flags.get("nigga").execute(message, args1);
}
});
question from:
https://stackoverflow.com/questions/65645260/flagging-words-in-discord-js 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…