discord-bot-template/modules/_deploy-global.js

38 lines
968 B
JavaScript
Raw Normal View History

2023-01-21 04:35:03 +00:00
// dotenv for handling environment variables
const dotenv = require('dotenv');
dotenv.config();
2023-02-13 04:51:17 +00:00
const { REST, Routes } = require('discord.js');
const botId = process.env.BOTID;
2023-01-21 04:35:03 +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-02-13 04:51:17 +00:00
const command = require(`../slash-commands/${file}`);
2023-01-21 04:35:03 +00:00
if (command.data != undefined) {
commands.push(command.data.toJSON());
}
}
2023-02-13 04:51:17 +00:00
console.log(`Token: ...${token.slice(-5)} | Bot ID: ${botId}`);
2023-01-21 04:35:03 +00:00
2023-02-13 04:51:17 +00:00
const rest = new REST({ version: '10' }).setToken(token);
2023-01-21 04:35:03 +00:00
(async () => {
try {
2023-02-13 04:51:17 +00:00
console.log('Started refreshing global application (/) commands.');
2023-01-21 04:35:03 +00:00
await rest.put(
2023-02-13 04:51:17 +00:00
Routes.applicationCommands(botId),
2023-01-21 04:35:03 +00:00
{ body: commands },
);
2023-02-13 04:51:17 +00:00
console.log('Successfully reloaded global application (/) commands.');
2023-01-21 04:35:03 +00:00
process.exit();
} catch (error) {
console.error(error);
}
})();