Shadow_Generator/deploy-commands.js

36 lines
No EOL
1.2 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.')
.addStringOption(option =>
option.setName('type')
.setDescription('The type of thing to generate.')
.setRequired(true)
.addChoices(
{ name: 'Host', value: 'host' },
{ name: 'Gang', value: 'gang' },
{ name: 'Corporation', value: 'corporation' },
)
)
]
.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);