· 4 years ago · Apr 07, 2021, 01:02 PM
1const fs = require('fs');
2const Discord = require('discord.js');
3const config = require('./config.json');
4
5const client = new Discord.Client();
6client.commands = new Discord.Collection();
7const commandFlies = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
8
9for (const file of commandFlies) {
10 const command = require(`./commands/${file}`);
11
12 // set a new item in the Collection
13 // with the key as the command name and the value as the exported value
14 client.commands.set(command.name, command);
15}
16
17client.once('ready', () => {
18 console.log(`Bot initialisé en temps que ${client.user.tag} !`);
19 client.user.setActivity('créer le futur').catch(console.error);
20});
21
22client.on('message', message => {
23 const args = message.content.slice(config.prefix.length).split(/ +/);
24 const commandName = args.shift().toLowerCase();
25
26 const command = client.commands.get(commandName) ||
27 client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
28 try {
29 command.execute(client, api, config, message, args);
30 }
31 catch (error) {
32 console.error(error);
33 message.reply('there was an error trying to execute the command!');
34
35 }
36});
37client.login(config.token)