0
votes

i am trying to write a event that will delete any message with specific key words but it is not doing anything.

client.on("message", (message) => {
  if (message.author.bot) return;
  if (message.member.roles.some(r => ["DEAN!"].includes(r.name))) return;
  let words = ["crack", "hack", "hacked", "patch", "patched", "crackd"]
  if (message.content.includes(words)) {
    message.channel.send(`${message.author} You cannot say such words!`);
    message.delete();
    console.log(chalk.bgYellow("INFO") + (` message containing restricted words by ${message.author} was deleted`));
  }
});
1

1 Answers

0
votes

Array.prototype.includes method does not accept an array as param. This method should be called on array with values and as first param - value you want to know if it is exist in array.

To recognize messages that contains banned keword, you should check all words in this message for your keywords. Like this:

function isMessageContainBannedWord(msg) {
  const bannedWords = [ 'banana', 'waterlemon' ]
  const words = msg.split(' ')

  return words.some((word) => bannedWords.includes(word))
}

console.log(isMessageContainBannedWord('I like apples'))
console.log(isMessageContainBannedWord('I want you to feel my banana power!'))