Changing commands to dynamic handling rather than if/else.
This commit is contained in:
+11
-7
@@ -1,14 +1,18 @@
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
const { clientId, guildId, token } = require('./config.json');
|
||||
|
||||
const commands = [
|
||||
new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'),
|
||||
new SlashCommandBuilder().setName('server').setDescription('Replies with server info!'),
|
||||
new SlashCommandBuilder().setName('user').setDescription('Replies with user info!'),
|
||||
]
|
||||
.map(command => command.toJSON());
|
||||
const commands = [];
|
||||
const commandsPath = path.join(__dirname, 'commands');
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath);
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(token);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user