Thin Mint
Thin Mint

Reputation: 23

How do i use a json as a variable

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?

Upvotes: 0

Views: 55

Answers (1)

Rom Grk
Rom Grk

Reputation: 536

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.

Upvotes: 1

Related Questions