26 lines
1,004 B
JavaScript
26 lines
1,004 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const Discord = require("discord.js");
|
|
const rest = new Discord.REST({ version: '9' }).setToken(process.env.TOKEN)
|
|
const colors = require("colors");
|
|
|
|
module.exports = async (client) => {
|
|
const commandsPath = path.join(__dirname, 'commands');
|
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
|
const commands = [];
|
|
|
|
for (const file of commandFiles) {
|
|
const filePath = path.join(commandsPath, file);
|
|
const command = require(filePath);
|
|
if (command.definition) commands.push(command.definition);
|
|
}
|
|
|
|
console.log(`${colors.cyan(`[INFO]`)} ${colors.green(`Found ${commands.length} commands.`)}`);
|
|
try {
|
|
//Global
|
|
console.log(`${colors.cyan(`[INFO]`)} ${colors.green(`Registering commands...`)}`);
|
|
await rest.put(Discord.Routes.applicationCommands(client.user.id), { body: commands })
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
} |