【问题标题】:Stop the wrest of the javascript code when it encounters a error without stopping the entire bot遇到错误时停止对 javascript 代码的争夺,而不停止整个机器人
【发布时间】:2022-01-23 14:38:28
【问题描述】:

您好,我正在运行第 12 版中的 discord.js 机器人,我想要它,所以如果它遇到错误,它会停止该命令的其余部分运行,而不会停止它自己的整个机器人 这是我当前的代码:

        async function startApp () {
            const currentUser = await noblox.setCookie(args.join(" "))
            .catch( (err) => { 
                message.channel.send("Invaild or Expired data")
                }) 
// rest of the program

【问题讨论】:

  • setCookie() 是否返回承诺?什么错误会使您的机器人崩溃?

标签: javascript error-handling discord discord.js


【解决方案1】:

你必须这样做

process.on("uncaughtException", console.error);

在您的机器人的索引中。这将在不停止机器人的情况下记录任何错误,无论错误如何(前提是您没有在机器人的某处执行process.exit())。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-06
    • 2021-10-19
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多