javascript - 禁用自动调节时机器人没有响应
问题描述
在我的 Discord 机器人上,如果用户希望机器人删除消息、踢用户、禁止用户或软禁止用户,用户可以选择不和谐邀请检测自动模式,所有这些都存储在 MongoDB 上。但是当用户在他们的公会上禁用 automod 时,它会停止响应所有命令,直到通过编辑 MongoDB 文件手动重新打开它
这是我的 message.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 来查看代码块的两个括号的位置,以便将来更轻松地解决此类问题.
希望我能帮上忙!
推荐阅读
- javascript - 即使我指定的是 en-gb,Bootstrap DateTimePicker 本地化也是 en-us
- c# - 使用 Entity Framework Core 从数据库中获取最大和最小记录
- javascript - 尝试在 Papa Parse 中使用工作人员时出现“未捕获的 ReferenceError:未定义窗口”
- arrays - 将 json 数组输出保存到 txt 文件并在尝试解析时出错
- c# - 如何使用对象列表而不是循环填充 SQL Server 数据库
- regex - Perl替换匹配模式上方一行中的字符串
- c# - 在 C# 中通过串行端口进行高速串行通信
- mysql - 运行查询时是否可以在导出 .csv 文件中硬编码下拉菜单?
- node.js - 角度形式组 patchValue 围绕值包装大括号
- node.js - 上传图片时出现错误 500(内部服务器错误)