Javascript 忽略允许的单词的消息筛选器
我一直在尝试重做一个消息过滤器有一段时间了,我被它难住了。我有一个不同类别的不同单词的列表,过滤器会阻止这些单词,但也有一个允许单词的位置,它会忽略这些单词。这是我的代码Javascript 忽略允许的单词的消息筛选器,javascript,discord.js,Javascript,Discord.js,我一直在尝试重做一个消息过滤器有一段时间了,我被它难住了。我有一个不同类别的不同单词的列表,过滤器会阻止这些单词,但也有一个允许单词的位置,它会忽略这些单词。这是我的代码 for (var i in curse) { if(msg.includes(curse[i])) { const filterViolation = new Discord.RichEmbed() .setColor('#ff0000')
for (var i in curse) {
if(msg.includes(curse[i])) {
const filterViolation = new Discord.RichEmbed()
.setColor('#ff0000')
.setAuthor(message.author.username, message.author.avatarURL)
.setTitle('Filter Violation')
.setDescription(`${rule} **Profanity.** \n${ifcont}`)
.setTimestamp()
.setFooter(copyright);
message.delete()
message.author.send(filterViolation).then(msg => {msg.delete(30000)})
message.channel.send(msgvio).then(msg => {msg.delete(15000)})
logger.write(logviolation)
}
}
for (var i in inap) {
if(msg.includes(inap[i])) {
const filterViolation = new Discord.RichEmbed()
.setColor('#ff0000')
.setAuthor(message.author.username, message.author.avatarURL)
.setTitle('Filter Violation')
.setDescription(`${rule} **Inappropriate Content.** \n${ifcont}`)
.setTimestamp()
.setFooter(copyright);
message.delete()
message.author.send(filterViolation).then(msg => {msg.delete(30000)})
message.channel.send(msgvio).then(msg => {msg.delete(15000)})
logger.write(logviolation)
}
}
for (var i in encvio) {
if(msg.includes(encvio[i])) {
const filterViolation = new Discord.RichEmbed()
.setColor('#ff0000')
.setAuthor(message.author.username, message.author.avatarURL)
.setTitle('Filter Violation')
.setDescription(`${rule} **Encouraging Violence or Hatred towards others.** \n${ifcont}`)
.setTimestamp()
.setFooter(copyright);
message.delete()
message.author.send(filterViolation).then(msg => {msg.delete(30000)})
message.channel.send(msgvio).then(msg => {msg.delete(15000)})
logger.write(logviolation)
}
}
for (var i in web) {
if(msg.includes(web[i])) {
const filterViolation = new Discord.RichEmbed()
.setColor('#ff0000')
.setAuthor(message.author.username, message.author.avatarURL)
.setTitle('Filter Violation')
.setDescription(`${rule} **Website Links or Advertising.** \n${ifcont}`)
.setTimestamp()
.setFooter(copyright);
message.delete()
message.author.send(filterViolation).then(msg => {msg.delete(30000)})
message.channel.send(msgvio).then(msg => {msg.delete(15000)})
logger.write(logviolation)
}
}
for (var i in racism) {
if(msg.includes(racism[i])) {
const filterViolation = new Discord.RichEmbed()
.setColor('#ff0000')
.setAuthor(message.author.username, message.author.avatarURL)
.setTitle('Filter Violation')
.setDescription(`${rule} **Racism.** \n${ifcont}`)
.setTimestamp()
.setFooter(copyright);
message.delete()
message.author.send(filterViolation).then(msg => {msg.delete(30000)})
message.channel.send(msgvio).then(msg => {msg.delete(15000)})
logger.write(logviolation)
}
}
for (var i in blacklistwords) {
if(msg.includes(blacklistwords[i])) {
const filterViolation = new Discord.RichEmbed()
.setColor('#ff0000')
.setAuthor(message.author.username, message.author.avatarURL)
.setTitle('Filter Violation')
.setDescription(`${rule} **Blacklisted Words Usage.** \n${ifcont}`)
.setTimestamp()
.setFooter(copyright);
message.delete()
message.author.send(filterViolation).then(msg => {msg.delete(30000)})
message.channel.send(msgvio).then(msg => {msg.delete(15000)})
logger.write(logviolation)
}
}
for (var i in allowed) {
if(msg.includes(allowed[i])) return;
}
例如,每当有人说“夜”这个词时,它都会将其视为种族主义,因为它会检查前3个字母,并将其视为种族主义,即使“夜”这个词在允许的单词列表中,也不确定我做错了什么。我试图让它忽略“夜晚”这个词(或者列表中的任何其他单词),但是继续检查这个消息。 在这个逻辑中,我有一点麻烦,但是我会考虑反转它。将消息拆分为一个单词数组,然后检查消息中的每个单词,查看它是否在黑名单中,而不在白名单中
让checkMessage=msg.split(“”);
for(设i=0;i
有没有办法去掉标点和空格,因为我确信人们会使用“s.hit”和“s h I t”等词?你可以用正则表达式替换一个.replace()。看起来有人在这里给出了答案:非常感谢,Tarazed:)