Shadow_Generator/deploy-commands.js

46 lines
No EOL
1.5 KiB
JavaScript

require('dotenv').config();
const { REST, SlashCommandBuilder, Routes } = require('discord.js');
const clientId = process.env.CLIENT_ID;
const guildId = process.env.GUILD_ID;
const token = process.env.TOKEN;
const commands = [
new SlashCommandBuilder()
.setName('generate')
.setDescription('Generate something.')
.addSubcommand(subcommand =>
subcommand
.setName('host')
.setDescription('Generate a host.')
.addNumberOption(option =>
option
.setName('rating')
.setDescription('The rating of the host.')
.setRequired(true)
)
.addStringOption(option =>
option
.setName('type')
.setDescription('The type of the host.')
.addChoices(
{ name: 'Foundation', value: 'foundation' },
{ name: 'Framework', value: 'framework' },
)
)
)
]
.map(command => command.toJSON());
const rest = new REST({ version: '10' }).setToken(token);
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
.then((data) => console.log('Removed all commands from guilds'))
.catch(console.error);
rest.put(Routes.applicationCommands(clientId), { body: [] })
.then((data) => console.log(`Removed all global commands`))
.catch(console.error);
rest.put(Routes.applicationCommands(clientId), { body: commands })
.then((data) => console.log(`Added ${data.length} commands to global`))
.catch(console.error);