2023-01-18 00:35:24 +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');
|
2023-02-20 01:42:14 +00:00
|
|
|
const clientId = process.env.BOTID;
|
2023-01-18 00:35:24 +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) {
|
2023-01-23 06:38:49 +00:00
|
|
|
const command = require(`../slash-commands/${file}`);
|
2023-01-18 00:35:24 +00:00
|
|
|
if (command.data != undefined) {
|
|
|
|
commands.push(command.data.toJSON());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 01:42:14 +00:00
|
|
|
console.log(`Token: ${token} Client ID: ${clientId}`);
|
2023-01-18 00:35:24 +00:00
|
|
|
|
|
|
|
const rest = new REST({ version: '9' }).setToken(token);
|
|
|
|
|
2023-02-20 01:42:14 +00:00
|
|
|
async function deleteCommands() {
|
2023-01-18 00:35:24 +00:00
|
|
|
try {
|
2023-02-20 01:42:14 +00:00
|
|
|
console.log('Started deleting application (/) commands.');
|
|
|
|
|
|
|
|
await rest.put(
|
|
|
|
Routes.applicationCommands(clientId),
|
|
|
|
{ body: "" },
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log('Successfully deleted application (/) commands.');
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function uploadCommands() {
|
|
|
|
try {
|
|
|
|
console.log('Started reloading application (/) commands.');
|
2023-01-18 00:35:24 +00:00
|
|
|
|
|
|
|
await rest.put(
|
|
|
|
Routes.applicationCommands(clientId),
|
|
|
|
{ body: commands },
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log('Successfully reloaded application (/) commands.');
|
|
|
|
process.exit();
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
2023-02-20 01:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(async () => {
|
2023-02-20 20:15:08 +00:00
|
|
|
// await deleteCommands();
|
2023-02-20 01:42:14 +00:00
|
|
|
await uploadCommands();
|
2023-01-18 00:35:24 +00:00
|
|
|
})();
|