-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-commands.js
More file actions
62 lines (50 loc) · 1.74 KB
/
Copy pathdeploy-commands.js
File metadata and controls
62 lines (50 loc) · 1.74 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Deploy slash commands to Discord
*
* Run this script to register/update slash commands:
* node deploy-commands.js
*/
const { REST, Routes } = require('discord.js');
const fs = require('fs');
const path = require('path');
require('dotenv').config();
const token = process.env.DISCORD_TOKEN;
const clientId = process.env.CLIENT_ID;
const guildId = process.env.GUILD_ID;
if (!token || !clientId || !guildId) {
console.error('Missing required environment variables');
console.error('Make sure DISCORD_TOKEN, CLIENT_ID, and GUILD_ID are set in .env');
process.exit(1);
}
const commands = [];
const commandsPath = path.join(__dirname, 'src', 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command) {
commands.push(command.data.toJSON());
console.log(`✧ loaded: ${command.data.name}`);
} else {
console.warn(`⚠ ${file} missing data property`);
}
}
const rest = new REST().setToken(token);
(async () => {
try {
console.log(`\n✧ deploying ${commands.length} commands...`);
// Deploy to specific guild (faster for development)
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log(`✧ successfully deployed ${data.length} commands`);
// List deployed commands
console.log('\ndeployed commands:');
for (const cmd of data) {
console.log(` /${cmd.name}`);
}
} catch (error) {
console.error('Deployment failed:', error);
}
})();