Anti Swear Or Bad Words System For Discord Bot 1

Anti Swear Or Bad Words System For Discord Bot

If you want anyone not to swear or send bad words in your server then you will be needing a anti swear system but if you do not have idea how to start or create this thing then this post will be very helpful for you.

Create a new file with name data.json where will be storing badwords

{
  "badwords": 
  [
  "Fuck",
    "Sucks",
    "Bitch"
  ]
}

Now Define the badwords in main file

const { badwords } = require("./data.json") 

Now go to message event and we will make permission statement in it so that owner or moderation can swear words :D, So for that we will check if author have permission or not.

 if(!message.member.hasPermission("ADMINISTRATOR")) {
   
 }

Now we will let a variable with name confirm and value false, then add for loop and check if message content contains any bad word or not and if contains any bad word then change confirm variable to true.

    let confirm = false;
   
    var i;
    for(i = 0;i < badwords.length; i++) {
      
      if(message.content.toLowerCase().includes(badwords[i].toLowerCase()))
        confirm = true;
      
    }

Now outside the loop we will check confirm value and if it get true then delete the author message and send warn message by bot.

  if(confirm) {
      message.delete()
      return message.channel.send("You are not allowed to send badwords here")
    }    

Video Tutorial

Source Code

Here is the resulted code – HERE

Leave a Reply

Your email address will not be published. Required fields are marked *