mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 23:36:35 +02:00
52 lines
2.2 KiB
JavaScript
52 lines
2.2 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
module.exports = (client) => {
|
|
const loadCommands = (dir) => {
|
|
let count = 0;
|
|
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 the cache for this command file
|
|
delete require.cache[require.resolve(filePath)];
|
|
const command = require(filePath);
|
|
client.commands.set(command.name, command);
|
|
count++;
|
|
} catch (error) {
|
|
console.error(`Failed to load file: ${filePath}`); // Log any errors
|
|
console.error(error);
|
|
}
|
|
}
|
|
});
|
|
return count;
|
|
}
|
|
|
|
const totalCommands = loadCommands('../commands');
|
|
console.log(`Commands => ${totalCommands} commandes préfixées chargées sur le bot`);
|
|
client.on('messageCreate', async message => {
|
|
//const botId = client.user.id;
|
|
//const guildId = message.guild.id;
|
|
//const prefix = botTokens.coins[botId].prefix;
|
|
const prefix = '!';
|
|
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
|
|
|
const args = message.content.slice(prefix.length).trim().split(/ +/);
|
|
const commandName = args.shift().toLowerCase();
|
|
if (!client.commands.has(commandName)) return;
|
|
const command = client.commands.get(commandName)
|
|
//|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
|
|
|
|
if (command) {
|
|
//const permissionLevel = await getPermissionLevel(message.member, client, guildId);
|
|
|
|
//console.log(permissionLevel, permissions[command.name])
|
|
//if (permissionLevel >= permissions[command.name]) {
|
|
command.execute(message, args, client);
|
|
//} else {
|
|
// return message.reply("Vous n'avez pas accès à cette commande.");
|
|
// }
|
|
}
|
|
});
|
|
}
|