all repos — simple-discord-music-bot @ cefe3a40891527715ded6ebf357cca292a5a67a8

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
 7const commands = new Array();
 8const commandsPath = path.join(process.cwd(), 'commands');
 9const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
10
11for (const file of commandFiles) {
12	const filePath = path.join(commandsPath, file);
13	const command = require(filePath);
14	commands.push(command.data.toJSON());
15}
16
17const rest = new REST({ version: '10' }).setToken(token);
18
19rest.put(Routes.applicationCommands(clientId), { body: commands })
20	.then((data) => console.log(`Successfully registered ${data.length} application commands.`))
21	.catch(console.error);