message.content.includes doesn't works (?)

656 views Asked by At
const banWord = ["meat","fruit","road"];
    for (var i = 0; i < banWord.length; i++) {
        if(message.content.includes(banWord[i])) {
            message.channel.send('Mohon yang sopan ya...');
        }
      }

the bot won't say anything at discord server when someone says that words.

2

There are 2 answers

0
bmp On

You need to put that script inside of a client function. For example:

client.on('message', message => {
    for (var i = 0; i < banWord.length; i++){
        if(message.content.includes(banWord[i])) {
            message.channel.send('Mohon yang sopan ya...')
        }
    }
})
0
FanBoy9344 On

I cannot remember the exact thing, but here is something off my memory. Instead of message.content.includes(), you might be able to use message.content.has(). Again, I am not sure, nor I can try right now. So, sorry in advance if it doesn't work