forked from mongoosejs/sample-apps
-
Notifications
You must be signed in to change notification settings - Fork 12
/
deploy-commands.js
37 lines (29 loc) · 1.16 KB
/
deploy-commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
require('dotenv').config();
const { Routes } = require('discord.js');
const { REST } = require('@discordjs/rest');
const assert = require('assert');
const fs = require('node:fs');
const path = require('node:path');
const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
const {
DISCORD_GUILD_ID: guildId,
DISCORD_CLIENT_ID: clientId,
DISCORD_TOKEN: token
} = process.env;
assert.ok(guildId, 'Must set DISCORD_GUILD_ID environment variable');
assert.ok(clientId, 'Must set DISCORD_CLIENT_ID environment variable');
assert.ok(token, 'Must set DISCORD_TOKEN environment variable');
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
console.log(filePath);
const command = require(filePath);
console.log(command);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(token);
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
.then((data) => console.log(`Successfully registered ${data.length} application commands.`))
.catch(console.error);