简体   繁体   English

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

[英]Try Catch in Discord.js does not catch

I have a command handler which should catch the errors if a error occurs when loading a command, but it does not catch the error.我有一个命令处理程序,如果在加载命令时发生错误,它应该捕获错误,但它不会捕获错误。 I need this, because my bot would crash any time there is a error and i dont want that.我需要这个,因为我的机器人会在出现错误时崩溃,而我不希望那样。

Here is the code of the module:这是模块的代码:

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)

    }
}

I found my mistake.我发现了我的错误。 No need for answer.无需回答。

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)

    }
}

I just forgot to const command = require( ./commands/utils/${file} ) in the TryCatch Block我只是忘了在 TryCatch 块中使用const command = require( ./commands/utils/${file} )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM