Update
This commit is contained in:
parent
87d24589d0
commit
c03d4a6043
1 changed files with 30 additions and 1 deletions
31
index.js
31
index.js
|
@ -3,6 +3,7 @@ const chalk = require('chalk');
|
|||
const fs = require('node:fs');
|
||||
const config = require('./configs/config.json');
|
||||
const path = require('node:path');
|
||||
const winston = require('winston');
|
||||
|
||||
// Discord Client Constructor
|
||||
const client = new Discord.Client({
|
||||
|
@ -67,24 +68,52 @@ async function registerSlashCommands() {
|
|||
}
|
||||
}
|
||||
|
||||
// Create a Winston logger
|
||||
const logger = winston.createLogger({
|
||||
level: 'error',
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.json()
|
||||
),
|
||||
transports: [
|
||||
new winston.transports.File({ filename: 'error.log' }),
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.simple()
|
||||
)
|
||||
})
|
||||
],
|
||||
});
|
||||
|
||||
// Call the async function to register slash commands
|
||||
registerSlashCommands();
|
||||
|
||||
// Anti Crash
|
||||
process.on('unhandledRejection', (reason, p) => {
|
||||
logger.error('[antiCrash] :: Unhandled Rejection/Catch', { reason, p });
|
||||
console.log(chalk.bold.redBright('[antiCrash] :: Unhandled Rejection/Catch'));
|
||||
console.log(reason?.stack, p);
|
||||
});
|
||||
|
||||
process.on("uncaughtException", (err, origin) => {
|
||||
console.log(chalk.bold.redBright('[antiCrash] :: ncaught Exception/Catch'));
|
||||
logger.error('[antiCrash] :: Uncaught Exception/Catch', { err, origin });
|
||||
console.log(chalk.bold.redBright('[antiCrash] :: Uncaught Exception/Catch'));
|
||||
console.log(err?.stack, origin);
|
||||
});
|
||||
|
||||
process.on('uncaughtExceptionMonitor', (err, origin) => {
|
||||
logger.error('[antiCrash] :: Uncaught Exception/Catch (MONITOR)', { err, origin });
|
||||
console.log(chalk.bold.redBright('[antiCrash] :: Uncaught Exception/Catch (MONITOR)'));
|
||||
console.log(err?.stack, origin);
|
||||
});
|
||||
|
||||
// Optional: Add more specific error handling
|
||||
process.on('warning', (warning) => {
|
||||
logger.warn('[antiCrash] :: Warning detected', { warning });
|
||||
console.log(chalk.bold.yellowBright('[antiCrash] :: Warning detected'));
|
||||
console.log(warning?.stack);
|
||||
});
|
||||
|
||||
// Discord Client login
|
||||
client.login(config.Token);
|
||||
|
|
Loading…
Reference in a new issue