diff --git a/index.js b/index.js index 0e018a4..c676689 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ + + const Discord = require('discord.js'); const chalk = require('chalk'); const fs = require('node:fs'); @@ -16,10 +18,6 @@ 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')); @@ -27,7 +25,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')); @@ -37,7 +35,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')); @@ -62,7 +60,7 @@ async function registerSlashCommands() { console.log('Started registering slash commands.'); await rest.put( - `/applications/${APPLICATION_ID}/commands`, + '/applications/1199858077655126188/commands', // Replace {applicationId} with your bot's application ID { body: commands }, ); @@ -77,6 +75,7 @@ registerSlashCommands(); // Function to update the bot from GitHub repository async function updateBotFromGitHub() { + const git = simpleGit(path.resolve(__dirname)); try { @@ -92,6 +91,7 @@ async function updateBotFromGitHub() { // Restart the bot to apply changes process.exit(); + } catch (error) { console.error('Error updating bot from GitHub:', error); } @@ -99,7 +99,9 @@ async function updateBotFromGitHub() { // Function to check for updates at regular intervals function checkForUpdates() { - setInterval(updateBotFromGitHub, UPDATE_INTERVAL); + // 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); // Perform initial check for updates on bot startup updateBotFromGitHub(); @@ -115,7 +117,7 @@ process.on('unhandledRejection', (reason, p) => { }); process.on("uncaughtException", (err, origin) => { - console.log(chalk.bold.redBright('[antiCrash] :: Uncaught Exception/Catch')); + console.log(chalk.bold.redBright('[antiCrash] :: ncaught Exception/Catch')); console.log(err?.stack, origin); }); @@ -125,4 +127,4 @@ process.on('uncaughtExceptionMonitor', (err, origin) => { }); // Discord Client login -client.login(config.Token); +client.login(config.Token); \ No newline at end of file