-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-commands.js
97 lines (85 loc) · 3.58 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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const fs = require('node:fs');
const path = require('node:path');
const { REST, Routes } = require('discord.js');
const paths = require("node:path");
require('dotenv').config();
const commands = [];
const commandsPath = path.join(__dirname, 'interactions', 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
let nbr = 0;
let nbr2 = 0;
async function registerBasicCommands() {
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
console.log("Commande détéctée: " + command.data.name + "✅")
commands.push(command.data.toJSON());
}
const commandsPathss = path.join(__dirname, 'interactions', 'contexts');
const commandFiless = fs.readdirSync(commandsPathss).filter(file => file.endsWith('.js'));
for (const file of commandFiless) {
const filePaths = path.join(commandsPathss, file);
const command = require(filePaths);
console.log("Commande détéctée: " + command.data.name + "✅")
commands.push(command.data.toJSON());
}
const files = fs.readdirSync(__dirname + "/" + "plugins");
nbr = files.length;
for (const file of files) {
fs.lstat(__dirname + "/" + "plugins" + "/" + file, (err, stats) => {
if (stats.isDirectory()) {
const pluginFolder = __dirname + "/" + "plugins" + "/" + file;
const commandsPath = pluginFolder + "/" + 'interactions' + "/" + 'commands';
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = commandsPath + "/" + file;
const command = require(filePath);
console.log("Commande détéctée: " + command.data.name + "✅")
commands.push(command.data.toJSON());
}
}
})
fs.lstat(__dirname + "/" + "plugins" + "/" + file, (err, stats) => {
if (stats.isDirectory()) {
const pluginFolder = __dirname + "/" + "plugins" + "/" + file;
const commandsPath = pluginFolder + "/" + 'interactions' + "/" + 'contexts';
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = commandsPath + "/" + file;
const command = require(filePath);
console.log(command)
console.log("Commande détéctée: " + command.data.name + "✅")
commands.push(command.data.toJSON());
}
}
})
nbr2++;
}
}
registerBasicCommands().then(async () => {
/*
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{body: []},
);
*/
let inter = setInterval(async () => {
if (nbr === nbr2){
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{body: commands},
); //console.log(r)
console.log('Successfully reloaded application (/) commands. ' + commands.length);
a();
}catch (e) {
console.log(e)
}
}
}, 1000)
function a(){
clearInterval(inter)
}
})