I want the uncaughtException and unhandledRejection events to log errors and send the error message in the same channel where the command was executed
function:
function ErrorLog(errortext, message) {
const ErrorEmbed = new MessageEmbed()
.setColor(`#${config["color"].error}`)
.setDescription(`${errortext}`)
message.channel.send({ embeds: [ErrorEmbed] })
return
}
event:
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);
});
However, it gives me an error saying Cannot read properties of undefined (reading 'send'), and I'm not exactly sure how to fix this.
CodePudding user response:
Just simply use try catch
try{
//your code
}catch(error){
console.log(error)
message.channel.send({content: error})
}
