【问题标题】:Bot not responding when automoderation is disabled禁用自动调节时机器人没有响应
【发布时间】:2021-05-15 21:56:27
【问题描述】:

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

这是我的 message.js 代码:

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

【问题讨论】:

    标签: javascript node.js mongoose discord discord.js


    【解决方案1】:

    这实际上是一个相对简单的错误,信不信由你。我以前犯过很多次这个错误,所以你并不孤单! 您的命令检测语句包含在 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 来查看代码块的两个括号的位置,这样您就可以更轻松地解决此类问题未来。

    希望我能帮上忙!

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 2021-05-25
      • 2021-08-18
      • 2020-08-09
      • 2021-11-03
      • 2021-01-06
      • 1970-01-01
      • 1970-01-01
      • 2023-02-10
      相关资源
      最近更新 更多