const fs = require('fs'); const chalk = require('chalk'); const { PermissionsBitField } = require('discord.js'); const { Routes } = require('discord-api-types/v9'); const { REST } = require('@discordjs/rest'); const AsciiTable = require('ascii-table'); const table = new AsciiTable().setHeading('Slash Commands', 'Status').setBorder('|', '-', '+', '+'); const token = process.env.TOKEN; const clientId = process.env.CLIENTID; const rest = new REST({ version: '9' }).setToken(token); module.exports.name = 'slashCommands'; module.exports = async (client) => { const slashCommands = []; fs.readdirSync('./slashCommands/').forEach(async dir => { const files = fs.readdirSync(`./slashCommands/${dir}`).filter(file => file.endsWith('.js')); for (const file of files) { const slashCommand = require(`../slashCommands/${dir}/${file}`); slashCommands.push({ name: slashCommand.name, description: slashCommand.description, type: slashCommand.type }); if (slashCommand.name) { client.slashCommands.set(slashCommand.name, slashCommand); table.addRow(file.split('.js')[0], chalk.green('Loaded')); } else { table.addRow(file.split('.js')[0], chalk.red('Failed')); } } }); console.log(chalk.blue(table.toString())); (async () => { try { await rest.put( Routes.applicationCommands(clientId), { body: slashCommands }, ); console.log(chalk.cyan('Successfully registered application commands.')); } catch (error) { console.error(chalk.red('Error while registering application commands:'), error); } })(); };