在 Discord.js 中尝试捕获未捕获

时间:2021-01-10 15:03:02

标签: javascript discord.js

我有一个命令处理程序,它应该在加载命令时发生错误时捕获错误,但它没有捕获错误。我需要这个,因为我的机器人会在出现错误时崩溃,而我不希望那样。

这是模块的代码:

for(const file of utilsCommandFiles) {
    try {
    const command = require(`./commands/utils/${file}`)
    console.log(`[INFORMATION] HYPX: Utils-Modul "${command.name}" wurde erfolgreich geladen.`)
    utilsCMDs.set(command.name, command)
    } catch(e) {
        const command = require(`./commands/utils/${file}`)
        console.error(`[ERROR] HYPX: Modul ${command.name} konnte nicht geladen werden.`)
        console.log(e)

    }
}

1 个答案:

答案 0 :(得分:0)

我发现了我的错误。无需回答。

for(const file of utilsCommandFiles) {
    try {
    const command = require(`./commands/utils/${file}`)
    commands.set(command.name, command)
    console.log(`[INFORMATION] HYPX: Utils-Modul "${command.name}" wurde erfolgreich geladen.`)
    } catch(e) {
        console.error(`[ERROR] HYPX: Modul konnte nicht geladen werden.`)
        console.log(e)

    }
}

我刚刚忘记在 TryCatch 块中 const command = require(./commands/utils/${file})

相关问题