From 0654a09a416daacb505d33c838648fb63b8e6841 Mon Sep 17 00:00:00 2001 From: shadow Date: Sun, 26 May 2024 20:16:13 -0400 Subject: [PATCH] Updated index.js --- index.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index c676689..0e018a4 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,3 @@ - - const Discord = require('discord.js'); const chalk = require('chalk'); const fs = require('node:fs'); @@ -18,6 +16,10 @@ const client = new Discord.Client({ ] }); +// Constants +const UPDATE_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours in milliseconds +const APPLICATION_ID = '1199858077655126188'; + // Event Handler console.log(chalk.bold.yellowBright('Loading Events')); const events = fs.readdirSync(`./events/`).filter(file => file.endsWith('.js')); @@ -25,7 +27,7 @@ for (const file of events) { const event = require(`./events/${file}`); client.on(file.split('.')[0], event.bind(null, client)); delete require.cache[require.resolve(`./events/${file}`)]; -}; +} // Message Command Handler console.log(chalk.bold.yellowBright('Loading Message Commands')); @@ -35,7 +37,7 @@ for (const file of messageCommands) { const command = require(`./commands/messages/${file}`); client.MessageCommands.set(command.name.toLowerCase(), command); delete require.cache[require.resolve(`./commands/messages/${file}`)]; -}; +} // Slash Command Handler console.log(chalk.bold.yellowBright('Loading Slash Commands')); @@ -60,7 +62,7 @@ async function registerSlashCommands() { console.log('Started registering slash commands.'); await rest.put( - '/applications/1199858077655126188/commands', // Replace {applicationId} with your bot's application ID + `/applications/${APPLICATION_ID}/commands`, { body: commands }, ); @@ -75,7 +77,6 @@ registerSlashCommands(); // Function to update the bot from GitHub repository async function updateBotFromGitHub() { - const git = simpleGit(path.resolve(__dirname)); try { @@ -91,7 +92,6 @@ async function updateBotFromGitHub() { // Restart the bot to apply changes process.exit(); - } catch (error) { console.error('Error updating bot from GitHub:', error); } @@ -99,9 +99,7 @@ async function updateBotFromGitHub() { // Function to check for updates at regular intervals function checkForUpdates() { - // Set an interval to check for updates (e.g., every 24 hours) - const interval = 24 * 60 * 60 * 1000; // 24 hours in milliseconds - setInterval(updateBotFromGitHub, interval); + setInterval(updateBotFromGitHub, UPDATE_INTERVAL); // Perform initial check for updates on bot startup updateBotFromGitHub(); @@ -117,7 +115,7 @@ process.on('unhandledRejection', (reason, p) => { }); process.on("uncaughtException", (err, origin) => { - console.log(chalk.bold.redBright('[antiCrash] :: ncaught Exception/Catch')); + console.log(chalk.bold.redBright('[antiCrash] :: Uncaught Exception/Catch')); console.log(err?.stack, origin); }); @@ -127,4 +125,4 @@ process.on('uncaughtExceptionMonitor', (err, origin) => { }); // Discord Client login -client.login(config.Token); \ No newline at end of file +client.login(config.Token);