Answer the question
In order to leave comments, you need to log in
How to check the presence of a word in a txt file?
I create a condition for the presence of prohibited words (in my case, links).
I already read the file with fs, but I don't know how to use this list.
Tell me please.
Answer the question
In order to leave comments, you need to log in
First, make an array of words from the read file, unless, of course, you have already done so.
Then, when a new message is received, through for go through all the words
//badWords - переменная, в которую, предположим, и записан этот массив
for (let word of badWords) {
if (message.content.includes(word)) {}
};
// запрещенные слова
array = ["ыва", "файл", "уй", "иг_Л"]
// регулярное выражение
blacklist = new RegExp(array.join("|"), 'gi')
text = /* содержимое прочитанного файла */
blacklist.test(text)
// true если найдено, false если нет
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question