我正在制作一个不和谐的机器人,我正在尝试使用数组制作一个禁用词列表。我似乎无法找到如何使这项工作。这是我当前的代码:
if (forbidenWords.includes(message.content)) {
message.delete();
console.log(colors.red(`Removed ${message.author.username}'s Message as it had a forbidden word in it.`));
}
如果你不知道,我正在尝试检查用户的消息是否包含数组
forbidenWords
中的任何内容并将其删除。我该怎么做呢?
最佳答案
在“现代” JS 中:
forbiddenWords.some(word => message.content.includes(word))
以注释的逐行格式:
forbiddenWords // In the list of forbidden words,
.some( // are there some
word => // words where the
message.content // message content
.includes( // includes
word)) // the word?
关于javascript - 如何检查消息内容是否包含数组中的任何项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41115137/