mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-04 07:46:36 +02:00
ajoute messageCreate
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'ping',
|
||||
description: 'Command to check the latency of the bot.',
|
||||
async execute(message, args, client) {
|
||||
message.channel.send('test');
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
name: 'messageCreate',
|
||||
async execute(client, message) {
|
||||
const prefix = '!'; // Assurez-vous que le préfixe est défini ici aussi
|
||||
|
||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
||||
|
||||
const args = message.content.slice(prefix.length).trim().split(/ +/);
|
||||
const commandName = args.shift().toLowerCase();
|
||||
|
||||
// Si la commande n'existe pas, ne faites rien
|
||||
if (!client.commands.has(commandName)) return;
|
||||
|
||||
const command = client.commands.get(commandName);
|
||||
|
||||
try {
|
||||
command.execute(client, message, args);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.reply('Il y a eu une erreur lors de l\'exécution de cette commande.');
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -2,13 +2,13 @@ const { Events, ActivityType } = require("discord.js")
|
||||
module.exports = {
|
||||
|
||||
name : Events.ClientReady,
|
||||
async run(client) {
|
||||
async execute(client) {
|
||||
|
||||
if (client.commands && Array.isArray(client.commands)) {
|
||||
client.application.commands.set(client.commands.map(command => command.data));
|
||||
} else {
|
||||
console.error('Les commandes du client sont manquantes ou mal formatées');
|
||||
}
|
||||
//if (client.commands && Array.isArray(client.commands)) {
|
||||
// client.application.commands.set(client.commands.map(command => command.data));
|
||||
//} else {
|
||||
//console.error('Les commandes du client sont manquantes ou mal formatées');
|
||||
//}
|
||||
console.log(`${client.user.username} est en ligne`);
|
||||
|
||||
},
|
||||
|
||||
@@ -25,4 +25,28 @@ module.exports = (client) => {
|
||||
|
||||
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.");
|
||||
// }
|
||||
}
|
||||
});
|
||||
}
|
||||
+21
-18
@@ -2,22 +2,25 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = (client) => {
|
||||
|
||||
let count = 0;
|
||||
const loadEvents = (dir) => {
|
||||
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
|
||||
const filePath = path.join(__dirname, dir, file);
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
loadEvents(path.join(dir, file));
|
||||
} else if (file.endsWith('.js')) {
|
||||
delete require.cache[require.resolve(filePath)];
|
||||
const event = require(filePath);
|
||||
client.on(event.name, (...args) => event.run(...args, client));
|
||||
console.log(`Event ${event.name} loaded`);
|
||||
count++;
|
||||
}
|
||||
});
|
||||
}
|
||||
loadEvents('../events');
|
||||
console.log(`Event => ${count} chargé sur le bot`)
|
||||
let count = 0;
|
||||
const loadEvents = (dir) => {
|
||||
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
|
||||
const filePath = path.join(__dirname, dir, file);
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
loadEvents(path.join(dir, file));
|
||||
} else if (file.endsWith('.js')) {
|
||||
delete require.cache[require.resolve(filePath)];
|
||||
const event = require(filePath);
|
||||
if (typeof event.execute === 'function') {
|
||||
client.on(event.name, (...args) => event.execute(...args, client));
|
||||
console.log(`Event ${event.name} loaded`);
|
||||
count++;
|
||||
} else {
|
||||
console.error(`Event ${event.name} does not have an execute method.`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
loadEvents('../events');
|
||||
console.log(`Event => ${count} chargé sur le bot`)
|
||||
}
|
||||
@@ -7,6 +7,9 @@ const client = new Client({intents: new IntentsBitField(3276799)});
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
});
|
||||
client.events = new Collection();
|
||||
client.commands = new Collection();
|
||||
client.snipes = new Collection();
|
||||
(async () => {
|
||||
await loadCommands(client);
|
||||
await loadEvents(client);
|
||||
|
||||
Reference in New Issue
Block a user