Updated index.js
This commit is contained in:
parent
f22a84f5d7
commit
0654a09a41
1 changed files with 10 additions and 12 deletions
20
index.js
20
index.js
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const fs = require('node:fs');
|
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
|
// Event Handler
|
||||||
console.log(chalk.bold.yellowBright('Loading Events'));
|
console.log(chalk.bold.yellowBright('Loading Events'));
|
||||||
const events = fs.readdirSync(`./events/`).filter(file => file.endsWith('.js'));
|
const events = fs.readdirSync(`./events/`).filter(file => file.endsWith('.js'));
|
||||||
|
@ -25,7 +27,7 @@ for (const file of events) {
|
||||||
const event = require(`./events/${file}`);
|
const event = require(`./events/${file}`);
|
||||||
client.on(file.split('.')[0], event.bind(null, client));
|
client.on(file.split('.')[0], event.bind(null, client));
|
||||||
delete require.cache[require.resolve(`./events/${file}`)];
|
delete require.cache[require.resolve(`./events/${file}`)];
|
||||||
};
|
}
|
||||||
|
|
||||||
// Message Command Handler
|
// Message Command Handler
|
||||||
console.log(chalk.bold.yellowBright('Loading Message Commands'));
|
console.log(chalk.bold.yellowBright('Loading Message Commands'));
|
||||||
|
@ -35,7 +37,7 @@ for (const file of messageCommands) {
|
||||||
const command = require(`./commands/messages/${file}`);
|
const command = require(`./commands/messages/${file}`);
|
||||||
client.MessageCommands.set(command.name.toLowerCase(), command);
|
client.MessageCommands.set(command.name.toLowerCase(), command);
|
||||||
delete require.cache[require.resolve(`./commands/messages/${file}`)];
|
delete require.cache[require.resolve(`./commands/messages/${file}`)];
|
||||||
};
|
}
|
||||||
|
|
||||||
// Slash Command Handler
|
// Slash Command Handler
|
||||||
console.log(chalk.bold.yellowBright('Loading Slash Commands'));
|
console.log(chalk.bold.yellowBright('Loading Slash Commands'));
|
||||||
|
@ -60,7 +62,7 @@ async function registerSlashCommands() {
|
||||||
console.log('Started registering slash commands.');
|
console.log('Started registering slash commands.');
|
||||||
|
|
||||||
await rest.put(
|
await rest.put(
|
||||||
'/applications/1199858077655126188/commands', // Replace {applicationId} with your bot's application ID
|
`/applications/${APPLICATION_ID}/commands`,
|
||||||
{ body: commands },
|
{ body: commands },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -75,7 +77,6 @@ registerSlashCommands();
|
||||||
|
|
||||||
// Function to update the bot from GitHub repository
|
// Function to update the bot from GitHub repository
|
||||||
async function updateBotFromGitHub() {
|
async function updateBotFromGitHub() {
|
||||||
|
|
||||||
const git = simpleGit(path.resolve(__dirname));
|
const git = simpleGit(path.resolve(__dirname));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -91,7 +92,6 @@ async function updateBotFromGitHub() {
|
||||||
|
|
||||||
// Restart the bot to apply changes
|
// Restart the bot to apply changes
|
||||||
process.exit();
|
process.exit();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating bot from GitHub:', 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 to check for updates at regular intervals
|
||||||
function checkForUpdates() {
|
function checkForUpdates() {
|
||||||
// Set an interval to check for updates (e.g., every 24 hours)
|
setInterval(updateBotFromGitHub, UPDATE_INTERVAL);
|
||||||
const interval = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
|
|
||||||
setInterval(updateBotFromGitHub, interval);
|
|
||||||
|
|
||||||
// Perform initial check for updates on bot startup
|
// Perform initial check for updates on bot startup
|
||||||
updateBotFromGitHub();
|
updateBotFromGitHub();
|
||||||
|
@ -117,7 +115,7 @@ process.on('unhandledRejection', (reason, p) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("uncaughtException", (err, origin) => {
|
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);
|
console.log(err?.stack, origin);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue