Updated index.js
This commit is contained in:
parent
0654a09a41
commit
2ab0442ad2
1 changed files with 12 additions and 10 deletions
20
index.js
20
index.js
|
@ -1,3 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
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');
|
||||||
|
@ -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
|
// 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'));
|
||||||
|
@ -27,7 +25,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'));
|
||||||
|
@ -37,7 +35,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'));
|
||||||
|
@ -62,7 +60,7 @@ async function registerSlashCommands() {
|
||||||
console.log('Started registering slash commands.');
|
console.log('Started registering slash commands.');
|
||||||
|
|
||||||
await rest.put(
|
await rest.put(
|
||||||
`/applications/${APPLICATION_ID}/commands`,
|
'/applications/1199858077655126188/commands', // Replace {applicationId} with your bot's application ID
|
||||||
{ body: commands },
|
{ body: commands },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -77,6 +75,7 @@ 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 {
|
||||||
|
@ -92,6 +91,7 @@ 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,7 +99,9 @@ async function updateBotFromGitHub() {
|
||||||
|
|
||||||
// Function to check for updates at regular intervals
|
// Function to check for updates at regular intervals
|
||||||
function checkForUpdates() {
|
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
|
// Perform initial check for updates on bot startup
|
||||||
updateBotFromGitHub();
|
updateBotFromGitHub();
|
||||||
|
@ -115,7 +117,7 @@ process.on('unhandledRejection', (reason, p) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("uncaughtException", (err, origin) => {
|
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);
|
console.log(err?.stack, origin);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue