eximiabots-radiox/src/client/commands.js

53 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-08-18 22:50:56 +00:00
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
2021-08-21 14:55:10 +00:00
const { token, version } = require('../config.js');
2021-08-18 22:50:56 +00:00
const fs = require('fs');
const path = require ('path');
module.exports = {
2021-08-21 14:55:10 +00:00
async execute(client) {
2021-08-18 22:50:56 +00:00
const commands = [];
const commandFiles = fs.readdirSync(path.join("./src/client/commands")).filter(f => f.endsWith(".js"));
for (const file of commandFiles) {
2021-08-21 14:55:10 +00:00
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
2021-08-18 22:50:56 +00:00
}
const rest = new REST({ version: '9' }).setToken(token);
(async () => {
2021-08-21 14:55:10 +00:00
try {
console.log('Started refreshing application (/) commands.');
if(version.includes("-dev")){
await rest.put(
Routes.applicationCommands(client.user.id),
{ body: [] },
);
let guilds = await client.guilds.fetch();
guilds.forEach(async guild => {
try {
await rest.put(
Routes.applicationGuildCommands(client.user.id, guild.id),
{ body: commands },
);
} catch (DiscordAPIError) {
}
});
} else {
await rest.put(
Routes.applicationCommands(client.user.id),
{ body: commands },
);
}
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
2021-08-18 22:50:56 +00:00
})();
}
}