【问题标题】:Discord.js V12 Rude words filter not workingDiscord.js V12 粗鲁的话过滤器不起作用
【发布时间】:2020-10-11 13:10:28
【问题描述】:

所以我像粗鲁的词过滤器一样添加,每当有人说那个词(小写或大写)时,它会删除他们的消息并回复一些内容,然后回复会在几秒钟内被删除。

这是我当前的代码,但它不会读取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 })
    })
}})

【问题讨论】:

    标签: javascript bots discord discord.js


    【解决方案1】:

    rudeWords 是一个数组,而不是字符串,因此您无法通过检查它们是否相等来比较 message.contentrudeWords,相反,您需要使用 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 })
        })
    }})
    

    【讨论】:

    • 不客气,欢迎来到 SO,如果答案解决了您的问题,请接受它,让其他人知道什么有效并且问题已得到解答。
    • 我会的,它说由于某种原因我需要等待 8 分钟.. 编辑:还有 5 个
    猜你喜欢
    • 2020-12-25
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 2021-03-02
    • 2021-01-18
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    相关资源
    最近更新 更多