voidbot/modules/_deploy-global.js

39 lines
970 B
JavaScript
Raw Normal View History

2023-02-10 04:25:25 +00:00
// dotenv for handling environment variables
const dotenv = require('dotenv');
dotenv.config();
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const clientId = process.env.BOTID;
2023-02-10 04:25:25 +00:00
const token = process.env.TOKEN;
const fs = require('fs');
const commands = [];
const commandFiles = fs.readdirSync('./slash-commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../slash-commands/${file}`);
2023-02-10 04:25:25 +00:00
if (command.data != undefined) {
commands.push(command.data.toJSON());
}
}
// console.log(commands);
2023-02-10 04:25:25 +00:00
const rest = new REST({ version: '9' }).setToken(token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
process.exit();
} catch (error) {
console.error(error);
}
})();