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

前端 未结 4 1352
一生所求
一生所求 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:25

    In "modern" JS:

    forbiddenWords.some(word => message.content.includes(word))
    

    In commented, line-by-line format:

    forbiddenWords               // In the list of forbidden words,
      .some(                     // are there some
        word =>                  // words where the 
          message.content        // message content
            .includes(           // includes
              word))             // the word?
    

提交回复
热议问题