0

im making a discord bot and am making a swear filter,

const swears = require("./words.json");

const swearWords = [swears];
if (swearWords.some(word => message.content.includes(word))) {
message.reply("BRUH NO NAUGHTEE WURDS");
message.delete().catch(e => {});
}

My Json is a list of swear words,

{
"words": [
 "example",
 "example2",
 "example3"
]}

but when someone swears nothing happens, could someone help me?

1
  • If you log console.log(swearWords) or console.log(Array.isArray(swearWords)) what do you get? Commented May 20, 2020 at 0:12

1 Answer 1

1

Here you go:

const swears = require("./words.json");

const swearWords = swears.words;

if (swearWords.some(word => message.content.includes(word))) {
  message.reply("BRUH NO NAUGHTEE WURDS");
  message.delete().catch(e => {});
}

When you require a JSON file it's basically as if you copy-paste the JSON code in place of the require(...) call.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much, ive been working on this for like 5 hours
If the answer helped you, go ahead and select it as the accepted answer. It's a nice reward for the person who took the time to answer your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.