require('module-alias/register');
const mongo = require('./mongo');
const { Client, Collection } = require('discord.js');
const client = new Client({ partials: ['MESSAGE', 'REACTION'] });
client.config = require('./config');
client.commands = new Collection();
const { registerEvents, registerCommands } = require('./utils/registry');
client.once('ready', async () => {
console.log(`Connected to Discord as ${client.user.tag}`);
await mongo().then(async () => console.log('Connected to Mongo'));
await registerEvents(client, '../events');
await registerCommands(client, '../commands');
updateBotStatus(); // Initial status update
// Update status when the bot joins or leaves a guild
client.on('guildCreate', updateBotStatus);
client.on('guildDelete', updateBotStatus);
});
client.login(client.config.token);
function updateBotStatus() {
const serverCount = client.guilds.cache.size;
const statusMessage = `Serving ${serverCount} servers`;
console.log(`Updating status to: ${statusMessage}`);
client.user.setPresence({
activities: [{ name: statusMessage, type: 'WATCHING' }],
status: 'online'
}).then(() => {
console.log('Status set successfully');
}).catch(console.error);
}