Discord.js V12 Rude words filter not working

自作多情 提交于 2021-01-28 03:41:44

问题


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.

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 })
    })
}})

回答1:


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 })
    })
}})


来源:https://stackoverflow.com/questions/62501455/discord-js-v12-rude-words-filter-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!