Skip to content
Snippets Groups Projects
registerCommands.js 1.12 KiB
Newer Older
const {Client, Intents} = require('discord.js');
const connectDB = require('./util/db');
const botConfig = {
    token: process.env.DISCORD_API_TOKEN,
    applicationID: process.env.DISCORD_APP_ID
};
const locale = require('./util/locale');
const registerCommands = require('./util/registerCommands');

// Initializing Database

connectDB()

// Initializing locales

locale.init();

// Loading discord client to get all guild IDs
const client = new Client({intents: [Intents.FLAGS.GUILDS]});

client.on('ready', () => {

    (async () => {
        try {
            console.log('Started refreshing application (/) commands.');

            const guildIDs = await client.guilds.cache.map(guild => guild.id);
            console.log(guildIDs)
            //Going through all guildIDs and registering the commands with each one.
            await Promise.all(guildIDs.map(async (guildID) => registerCommands(guildID, './commands')));

            console.log('Successfully reloaded application (/) commands.');
        } catch (error) {
            console.error(error);
        }
    })();
});
client.login(botConfig.token);