woomy-v2/bot/deploy.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-12-11 02:22:11 +00:00
// taken from https://discordjs.guide/
const { REST, Routes } = require('discord.js');
const { clientId, token } = require('../botconfig.json');
const read = require('fs-readdir-recursive');
const commands = [];
const commandFiles = read('./commands').filter(file => file.endsWith('.js'));
2023-08-01 00:58:27 +00:00
if (process.argv.length === 2) {
console.log('No guild ID provided, deployment failed.');
process.exit(1);
}
const guildId = process.argv[2];
2022-12-11 02:22:11 +00:00
for (const file of commandFiles) {
2022-12-12 01:25:48 +00:00
const command = new (require(__dirname + '/commands/' + file))(file.substr(file.indexOf('/') + 1).slice(0, -3), file.substr(0, file.indexOf('/')));
commands.push({
name: command.name,
description: command.description,
options: command.options,
permissions: command.permissions,
dm_permission: command.dm_permission
});
2022-12-11 02:22:11 +00:00
}
const rest = new REST({ version: '10' }).setToken(token);
(async () => {
2022-12-12 01:25:48 +00:00
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
2022-12-11 02:22:11 +00:00
2022-12-12 01:25:48 +00:00
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
2022-12-11 02:22:11 +00:00
2022-12-12 01:25:48 +00:00
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
2022-12-11 02:22:11 +00:00
})();