all repos — simple-discord-music-bot @ 97d143480c5e930b650d03144851f59a790715c6

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);