Shadow_Generator/deploy-commands.js

46 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2022-10-07 12:02:35 +02:00
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 = [
2022-10-07 13:54:17 +02:00
new SlashCommandBuilder()
.setName('generate')
.setDescription('Generate something.')
2022-10-07 14:36:12 +02:00
.addSubcommand(subcommand =>
subcommand
.setName('host')
.setDescription('Generate a host.')
.addNumberOption(option =>
option
.setName('rating')
.setDescription('The rating of the host.')
.setRequired(true)
2022-10-07 13:54:17 +02:00
)
2022-10-07 14:36:12 +02:00
.addStringOption(option =>
option
.setName('type')
.setDescription('The type of the host.')
.addChoices(
{ name: 'Foundation', value: 'foundation' },
{ name: 'Framework', value: 'framework' },
)
)
)
2022-10-07 12:02:35 +02:00
]
.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);
2022-10-07 13:54:17 +02:00
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);