[英]Using message.channel.send in uncaughtException event
我希望 uncaughtException 和 unhandledRejection 事件記錄錯誤並在執行命令的同一通道中發送錯誤消息
function:
function ErrorLog(errortext, message) {
const ErrorEmbed = new MessageEmbed()
.setColor(`#${config["color"].error}`)
.setDescription(`${errortext}`)
message.channel.send({ embeds: [ErrorEmbed] })
return
}
事件:
process.on("unhandledRejection", ({ err, message }) => {
ErrorLog(`An unknown and unexpected error has occurred! \`\`\`${err}\`\`\``, message)
console.log(`An unknown and unexpected error has occurred! ${err}`);
process.exit(1);
});
但是,它給了我一個錯誤,說Cannot read properties of undefined (reading 'send')
,我不完全確定如何解決這個問題。
只需簡單地使用try catch
try{
//your code
}catch(error){
console.log(error)
message.channel.send({content: error})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.