How do I check if message content includes any items in an array?

前端 未结 4 1405
一生所求
一生所求 2021-01-03 11:25

I\'m making a discord bot and I\'m trying to make a forbidden words list using arrays. I can\'t seem to find out how to make this work. Here\'s my current code:



        
4条回答
  •  臣服心动
    2021-01-03 12:11

    You can use indexOf() method instead:

    if (forbidenWords.indexOf(message.content) != -1){
         message.delete();
         console.log(colors.red(`Removed ${message.author.username}'s Message as it had a forbidden word in it.`));
    }
    

提交回复
热议问题