-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-commands.cjs
More file actions
62 lines (50 loc) · 1.6 KB
/
deploy-commands.cjs
File metadata and controls
62 lines (50 loc) · 1.6 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-commands.cjs
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const dotenv = require('dotenv');
const fs = require('fs');
const path = require('path');
dotenv.config();
const token = process.env.BOT_TOKEN;
const clientId = process.env.CLIENT_ID;
if (!token || !clientId) {
console.error("❌ BOT_TOKEN ou CLIENT_ID est manquant dans le fichier .env");
process.exit(1);
}
const commands = [];
const commandsPath = path.join(__dirname, 'commands');
// Lecture récursive (avec ou sans sous-dossiers)
const walk = (dir) => {
const files = fs.readdirSync(dir);
for (const file of files) {
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
walk(fullPath);
} else if (file.endsWith('.cjs')) {
const command = require(fullPath);
if (command.data && typeof command.data.toJSON === 'function') {
commands.push(command.data.toJSON());
console.log(`✅ Chargé : ${command.data.name}`);
} else {
console.warn(`⚠️ Skipped (non valide) : ${file}`);
}
}
}
};
walk(commandsPath);
// Initialiser REST
const rest = new REST({ version: '9' }).setToken(token);
// Déploiement global
(async () => {
try {
console.log(`🚀 Déploiement de ${commands.length} commande(s) globales...`);
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands }
);
console.log('✅ Commandes slash déployées avec succès.');
} catch (error) {
console.error('❌ Erreur lors du déploiement :', error);
}
})();