eximiabots-radiox/src/client/commands.js

67 lines
2.4 KiB
JavaScript
Raw Normal View History

const { SlashCommandBuilder } = require('@discordjs/builders');
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}`);
command.data = new SlashCommandBuilder()
.setName(command.name)
.setDescription(command.description);
2021-08-26 18:50:15 +00:00
command.data = command.data.toJSON();
if(command.options) {
command.options.forEach(function(option) {
if(option.type == "STRING") option.type = 3;
command.data.options.push(option);
});
}
commands.push(command.data);
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 {
2021-08-22 17:49:11 +00:00
client.funcs.logger('Slash Commands', 'Started refreshing application (/) commands.');
2021-08-21 14:55:10 +00:00
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 },
);
}
2021-08-22 17:49:11 +00:00
client.funcs.logger('Slash Commands', 'Successfully reloaded application (/) commands.' + "\n");
2021-08-21 14:55:10 +00:00
} catch (error) {
2021-08-22 17:49:11 +00:00
client.funcs.logger('Slash Commands', 'Reloading application (/) commands failed.' + "\n");
2021-08-21 14:55:10 +00:00
console.error(error);
}
2021-08-18 22:50:56 +00:00
})();
}
}