Reputation:
I want to block swear words using my Discord Bot. So, I've created a JSON file of the ones I want to block and named it swear_words
. As a test, I've added sware to test. Then I include it at the top of my bot.js
file:
const { swear_words, mute_content } = require(`./swear-words.json`);
And then my blocking code, at the bottom:
client.on(`message`, message => {
for (var i=0; i < swear_words.length; i++) {
if (message.content.includes(swear_words[i])) {
message.delete();
message.channel.send(mute_content);
console.log("Someone tried to swear.");
}
}
});
That works when I type sware
, but not Sware
. So I add swear_words.prototype.toLowerCase()
to make:
if (message.content.includes(swear_words.prototype.toLowerCase() === swear_words[i])) {}
and then I get:
TypeError: Cannot read property 'toLowerCase' of undefined
What is this? Can it not read my JSON?
Thanks in advance for any help.
Upvotes: 2
Views: 1369
Reputation: 304
Use .toLowerCase( )
on the message content, as it returns a string.
if (message.content.toLowerCase( ).includes(swear_words[i])) {
Upvotes: 1