all repos — simple-discord-music-bot @ 394cdf4f8bb25b2fdc6eb4a21d67aa1b4bff9db8

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 { applicationId, token } = require(path.join(process.cwd(), 'config.json'));
 6const permissions = 17825792
 7
 8if (!(applicationId && token))
 9	throw 'Check your config.json!';
10
11const commands = new Array();
12const commandsPath = path.join(process.cwd(), 'commands');
13const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
14
15for (const file of commandFiles) {
16	const filePath = path.join(commandsPath, file);
17	const command = require(filePath);
18	commands.push(command.data.toJSON());
19}
20
21const rest = new REST({ version: '10' }).setToken(token);
22rest.put(Routes.applicationCommands(applicationId), { body: commands })
23	.then((data) => console.log(`
24Successfully registered ${data.length} application commands.
25Bot invite link: https://discord.com/api/oauth2/authorize?client_id=${applicationId}&permissions=${permissions}&scope=bot`))
26	.catch(console.error);