你好,我目前正试图用try-catch语句捕获一个discord-api错误
然而,由于某种原因,这不起作用,我的应用程序仍然停止执行,并给我以下消息
There was an uncaught error DiscordAPIError: Cannot send messages to this user // Example
如何用try-and-catch块捕获api错误,并且在调用函数后无法使用.catch表达式
这是我的代码
try {
interaction.user.send("Remember")
}
catch(DiscordAPIError) {
console.log("Oh no")
}
如果你想使用同步try/catch块,你需要把它放在一个异步函数中,等待interaction.user.send
:的承诺
await interaction.user.send("Remember")