function getErrorInfo(error) { const stackLines = error.stack.split('\n').slice(1); const firstStackLine = stackLines[0].trim(); const match = firstStackLine.match(/at [^(]+ \((.*):(\d+):(\d+)\)/); if (match) { const [, file, line, column] = match; return { file, line, column, message: error.message }; } return { file: 'N/A', line: 'N/A', column: 'N/A', message: error.message }; } process.on('unhandledRejection', async (err, promise) => { console.error(`[ANTI-CRASH] Unhandled Rejection: ${err.stack} | This error has been logged`.red); const errorInfo = getErrorInfo(err); client.channels.cache.get('1091136362666791002').send(`<@802325785507397672> **Unhandled Rejection**\n\nError: \`${errorInfo.message}\`\nFile: \`${errorInfo.file}\`\nLine: \`${errorInfo.line}\``); }); process.on('uncaughtException', async (err, promise) => { console.error(`[ANTI-CRASH] Uncaught Exception: ${err.stack} | This error has been logged`.red); const errorInfo = getErrorInfo(err); client.channels.cache.get('1091136362666791002').send(`<@802325785507397672> **Uncaught Exception**\n\nError: \`${errorInfo.message}\`\nFile: \`${errorInfo.file}\`\nLine: \`${errorInfo.line}\``); }); process.on('exit', (code) => { console.log(`[ANTI-CRASH] Process exited with code: ${code}`.green); client.channels.cache.get('1091136362666791002').send(`<@802325785507397672> **Process Exited**\n\nExit Code: \`${code}\``); }); process.on('uncaughtExceptionMonitor', (err, origin) => { console.error(`[ANTI-CRASH] Uncaught Exception Monitor: ${err.stack} | This error has been logged`.red); const errorInfo = getErrorInfo(err); client.channels.cache.get('1091136362666791002').send(`<@802325785507397672> **Uncaught Exception Monitor**\n\nError: \`${errorInfo.message}\`\nFile: \`${errorInfo.file}\`\nLine: \`${errorInfo.line}\``); });