mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-06 06:10:39 +02:00
grand commit que tutur attend ( marche pas le raidmode en dev)
sinon il y a pleins de truc comme les anti raid , des coorectif ect
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
module.exports = {
|
||||
name: 'reload',
|
||||
description: 'Recharge une commande spécifique',
|
||||
@@ -8,25 +10,35 @@ module.exports = {
|
||||
const commandName = args[0].toLowerCase();
|
||||
const command = message.client.commands.get(commandName);
|
||||
if (args[0].toLowerCase() === 'all') {
|
||||
message.reply('Toutes les commandes vont être rechargées.')
|
||||
message.reply('Toutes les commandes vont être rechargées....')
|
||||
.then(async sendmessage => {
|
||||
const commands = Array.from(message.client.commands.values());
|
||||
const reloadPromises = commands.map(async (command) => {
|
||||
const commandFile = command.file;
|
||||
delete require.cache[require.resolve(commandFile)];
|
||||
|
||||
try {
|
||||
const newCommand = require(commandFile);
|
||||
newCommand.file = commandFile;
|
||||
message.client.commands.set(newCommand.name, newCommand);
|
||||
await sendmessage.edit(`La commande ${newCommand.name} a été rechargée.`);
|
||||
} catch (error) {
|
||||
console.error(`Erreur lors du rechargement de la commande ${command.name}:`, error);
|
||||
await message.reply(`Une erreur est survenue lors du rechargement de la commande ${command.name}: ${error.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all(reloadPromises);
|
||||
message.client.commands.clear();
|
||||
let count = 0;
|
||||
const loadCommands = (dir) => {
|
||||
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
|
||||
const filePath = path.join(__dirname, dir, file);
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
count += loadCommands(path.join(dir, file));
|
||||
} else if (file.endsWith('.js')) {
|
||||
try {
|
||||
delete require.cache[require.resolve(filePath)];
|
||||
const command = require(filePath);
|
||||
command.file = filePath;
|
||||
message.client.commands.set(command.name, command);
|
||||
if (command.aliases) {
|
||||
command.aliases.forEach(alias => {
|
||||
message.client.commands.set(alias, command);
|
||||
});
|
||||
}
|
||||
count++;
|
||||
} catch (error) {
|
||||
console.error(`Failed to load file: ${filePath}`);
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
loadCommands('../../commands');
|
||||
await sendmessage.edit('Toutes les commandes ont été rechargées.');
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
Reference in New Issue
Block a user