Ulas GokDenîz Ulas GokDenîz - 1 year ago 64
Node.js Question

Using includes() to get a search value from a var

The below code is my attempt to gain the searchvalue from the variable "BannedWords", it doesn't work. This code uses the discord.js library. Here is it's documentation.

var BannedWords = [

if(msg.content.includes(BannedWords[msg.content.toUpperCase()])) {

Answer Source

You can achieve this with a regular expression:

if (new RegExp(BannedWords.join("|"), "i").test(msg.content)) {

Or using some:

if (BannedWords.some((v) => msg.content.toUpperCase().indexOf(v) >= 0)) {

Note: this is adapted to your (case insensitive) scenario from this very good answer. Refer to it for a better understanding.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download