首页 > 解决方案 > 禁用自动调节时机器人没有响应

问题描述

在我的 Discord 机器人上,如果用户希望机器人删除消息、踢用户、禁止用户或软禁止用户,用户可以选择不和谐邀请检测自动模式,所有这些都存储在 MongoDB 上。但是当用户在他们的公会上禁用 automod 时,它会停止响应所有命令,直到通过编辑 MongoDB 文件手动重新打开它

这是我的 message.js 代码:

https://haste.pancake.gg/ludiritaga.js

标签: javascriptnode.jsmongoosediscorddiscord.js

解决方案


这实际上是一个相对简单的错误,信不信由你。我以前犯过很多次这个错误,所以你并不孤单!您的命令检测语句包含在 if(linkDetect === `on`) {...} 语句中。

        )}}}} //Add a closing bracket here. This will exclude the portion of code that operates command detection from the else-if statement that checks if invite detection is on, allowing commands to be used while the feature is disabled.
        



    if (!message.content.toLowerCase().startsWith(prefix)) return;

    const args = message.content.substring(prefix.length).split(' ');

    const command =
        client.commands.get(args[0].toLowerCase()) ||
        client.commands.find(
            (cmd) => cmd.aliases && cmd.aliases.includes(args[0].toLowerCase())
        );
    if (!command) return;
        try {
    command.execute(message, args, client);
        }
        catch(err) {
            console.log(err)
            const errorEmbed = new MessageEmbed()
                .setColor('RED')
                .setDescription('**<:xmark:763662710130737152> There was an error, please report it in my [support server](https://discord.gg/q4dunRn).**\n\n' + `\`${err}\``)
            message.channel.send(errorEmbed)
        }
    } //Remove this bracket, as it is unnecessary once you add an additional closing bracket as suggested above. This bracket originally closed the else-if statement that only ran when invite detection was enabled
}

此外,为避免将来出现这种情况(如果您还没有这样做),您可以使用 IDE 来查看代码块的两个括号的位置,以便将来更轻松地解决此类问题.

希望我能帮上忙!


推荐阅读