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('ping').setDescription('Replies with pong!'), new SlashCommandBuilder().setName('server').setDescription('Replies with server info!'), new SlashCommandBuilder().setName('user').setDescription('Replies with user info!'), ] .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.applicationGuildCommands(clientId, guildId), { body: commands }) .then((data) => console.log(`Successfully registered ${data.length} application commands.`)) .catch(console.error);