const { Routes } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('@discordjs/rest');
const token = process.env.DISCORD_TOKEN;
const clientId = process.env.clientId;
const guildId = process.env.devGuildId;
const rest = new REST({ version: '10' }).setToken(token);
let curCommands, curDevCommands, newCommands, newDevCommands, commandsPath, commandFiles, file, command;
newCommands = newDevCommands = curCommands = curDevCommands = [];
// for global commands
// get current commands
rest.get(Routes.applicationCommands(clientId))
.then(() =>
// Not sure what goes here
)
.catch(logger.error);
curCommands =
commandsPath = path.join(__dirname, './commands');
commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js') && !file.startsWith('._'));
for (file of commandFiles) {
command = require(`./commands/${file}`);
newCommands.push(command.data.toJSON());
}
logger.debug("Global commands:" + newCommands);
rest.put(Routes.applicationCommands(clientId), { body: newCommands })
.then(() => logger.info('Successfully registered ' + newCommands.length + ' global commands.'))
.catch(logger.error);
for (let commandi of newCommands) {
console.group(commandi.name);
console.log(commandi.description);
if (commandi.options) {
for (let option of commandi.options) {
console.log(option.name + ": " + option.description);
}
}
console.groupEnd();
}
// SAME FOR Guild Commands
const { Routes } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('@discordjs/rest');
const token = process.env.DISCORD_TOKEN;
const clientId = process.env.clientId;
const guildId = process.env.devGuildId;
const rest = new REST({ version: '10' }).setToken(token);
let curCommands, curDevCommands, newCommands, newDevCommands, commandsPath, commandFiles, file, command;
newCommands = newDevCommands = curCommands = curDevCommands = [];
// for global commands
// get current commands
rest.get(Routes.applicationCommands(clientId))
.then(() =>
// Not sure what goes here
)
.catch(logger.error);
curCommands =
commandsPath = path.join(__dirname, './commands');
commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js') && !file.startsWith('._'));
for (file of commandFiles) {
command = require(`./commands/${file}`);
newCommands.push(command.data.toJSON());
}
logger.debug("Global commands:" + newCommands);
rest.put(Routes.applicationCommands(clientId), { body: newCommands })
.then(() => logger.info('Successfully registered ' + newCommands.length + ' global commands.'))
.catch(logger.error);
for (let commandi of newCommands) {
console.group(commandi.name);
console.log(commandi.description);
if (commandi.options) {
for (let option of commandi.options) {
console.log(option.name + ": " + option.description);
}
}
console.groupEnd();
}
// SAME FOR Guild Commands