-1

I have a large profanity list, as an array. Since this list is so big, I don't want it in my main file, but externally. I want something like this:

const blacklist = require(./blacklist.js)

And currently it is something like this:

const blacklist = [
"1",
"2",
"3"
]

The rest of the code here is:

 blacklist.forEach((word) => {
      if (message.content.toLowerCase().includes(word));
      message.delete();
      message.channel.send("Let's try to keep it family friendly!");

And will that last piece of code still work?

2
  • You need to export your constant somehow. How you do it depends on what module system you use. If you use standard JS, you just need to write export const ... and then in your other file you can write import {blacklist} from './filepath'. Commented Jan 21, 2022 at 15:53
  • You can read more about the module system here: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules Commented Jan 21, 2022 at 15:54

1 Answer 1

1

Discord.js is based on NodeJS, so:

blacklist.js :

module.exports =
[
    "1",
    "2",
    "3"
]

app.js :

const blacklist = require('./blacklist.js');
blacklist.forEach(word => { console.log(word) });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.