'Using message.channel.send in uncaughtException event

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source