People curse too much in your discord server?
Use this npm package to censor their messages and keep your discord server friendly for all ages (unless you wanted to ....)
npm i discord-censor
yarn add discord-censor
The package has total 3 features (just click on any of them to know more)
Β A function to check for those words in messages (check)
Β A function to replace bad words from messages (censor)
Β An array for bad words (badwords)
This package is tailored to be used with discord.js
It is a very handy function and returns value as true or false
To understand it better, see the code example below
const censor = require('discord-censor');
const CurseOrNot = censor.check("Is it a curse?")
console.log(CurseOrNot) //Prints False
const censor = require('discord-censor');
const CurseOrNot = censor.check("Is it a fuckin curse?")
console.log(CurseOrNot) //Prints true
This function will check for curses and replaces them by itself
It has two parameters
const censor = require('discord-censor');
censor.censor('The string you want to censor', 'censored word will be replaced by this (This parameter is optional)')
For more information, let's see the example code below
const censor = require('discord-censor');
const censored = censor.censor('I am fuckin cursing right now')
console.log(censored) //prints "I am f***in cursing right now"
Or if you want to completely remove the word, you can use 2nd parameter of this function
const censor = require('discord-censor');
const censored = censor.censor('I am fuckin cursing right now', '**curse**')
console.log(censored) //prints "I am **curse** cursing right now"
You might want to interact with the badwords array to change it's content if needed.
By default, it has 500 about bad words stored in it
To interact with the array, see the code example below
const censor = require('discord-censor');
console.log(censor.badwords) //prints all the badwords in the array
const index = censor.badwords.indexOf('Word'); // Replace word with any word you would like to remove from array
censor.badwords.splice(index, 1); //Removes 'Word' from array
Just combine the codes above and use the module in your discord bot.
For more information, let's see the example code below
const censor = require('discord-censor');
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if(censor.check(message.content) == true){ //Check if message has curses or not
const censored = censor.censor(message.content) //Censor the message if they have curses
message.channel.send(`${message.author.username} said ${censored}`) //Send the censored version of message
message.delete() //Delete the original of message version which has curses
} //That's all you have to do to censor messages in discord π
});
client.login('your-token-goes-here');