Discord.js V12粗鲁单词过滤器不起作用 [英] Discord.js V12 Rude words filter not working
问题描述
所以我要添加一个粗鲁的单词过滤器,每当有人说出某个单词(小写或大写)时,它都会删除其消息并回复某些内容,然后在几秒钟内删除回复.
so I am adding like a rude words filter, whenever someone says that word (lowercase or uppercase) it deletes their message and replies back with something and then the reply gets deleted in a few seconds.
这是我当前的代码,但是当我在聊天室中写任何粗鲁的单词时,它不会读取 rudeWords
,并且不会执行任何操作.
Here's my current code, but it doesn't read the rudeWords
and doesn't do anything when I write any of the rude words in the chat.
client.on('message', message => {
if (message.author.bot) return;
let rudeWords = ["kys", "kill yourself"];
if (message.content.toLowerCase() === rudeWords) {
message.delete()
message.reply('do not use that word here, thank you.').then(msg => {
msg.delete({ timeout: 3000 })
})
}})
推荐答案
rudeWords
是一个数组,而不是字符串,因此您无法将 message.content
与<通过检查它们是否相等来对code> rudeWords 进行替代,您需要使用 includes()
rudeWords
is an array, not a string so you can't compare message.content
to rudeWords
by checking if they're equal, instead, you need to use includes()
client.on('message', message => {
if (message.author.bot) return;
let rudeWords = ["kys", "kill yourself"];
if (rudeWords.includes(message.content.toLowerCase())) {
message.delete()
message.reply('do not use that word here, thank you.').then(msg => {
msg.delete({ timeout: 3000 })
})
}})
这篇关于Discord.js V12粗鲁单词过滤器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!