所以我要添加一个粗鲁的单词过滤器,每当有人说出某个单词(小写或大写)时,它都会删除其消息并回复某些内容,然后在几秒钟内删除回复。
这是我当前的代码,但是当我在聊天中输入任何粗鲁的单词时,它不会读取rudeWords
,并且不会执行任何操作。
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 })
})
}})
答案 0 :(得分:2)
rudeWords
是一个数组,而不是字符串,因此您无法通过检查它们是否相等来比较message.content
与rudeWords
,而需要使用{{1} }
includes()