問題描述
所以我像粗魯的詞過濾器一樣添加,每當有人說那個詞(小寫或大寫)時,它會刪除他們的消息并回復一些內容,然后回復會在幾秒鐘內被刪除.
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
與 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 粗魯的話過濾器不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!