all repos — simple-discord-music-bot @ 150cab4bd1dd3d852b5e00f38fd890fc95923c63

A Discord bot making use of discord.js and play-yt.

tools/deploy-commands.js (view raw)

 1const fs = require('node:fs');
 2const path = require('node:path');
 3const { Routes } = require('discord.js');
 4const { REST } = require('@discordjs/rest');
 5const { clientId, token } = require(path.join(process.cwd(), 'config.json'));
 6
 7if (!(clientId && token))
 8	throw 'Check your config.json!';
 9
10const commands = new Array();
11const commandsPath = path.join(process.cwd(), 'commands');
12const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
13
14for (const file of commandFiles) {
15	const filePath = path.join(commandsPath, file);
16	const command = require(filePath);
17	commands.push(command.data.toJSON());
18}
19
20const rest = new REST({ version: '10' }).setToken(token);
21
22rest.put(Routes.applicationCommands(clientId), { body: commands })
23	.then((data) => console.log(`Successfully registered ${data.length} application commands.`))
24	.catch(console.error);