-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
68 lines (55 loc) · 1.76 KB
/
index.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
const fs = require('fs');
const Discord = require('discord.js');
const { token, prefix } = require('./config.json');
const client = new Discord.Client();
client.commands = new Discord.Collection();
/* const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
*/
fs.readdir('./commands/', (err, folders) => {
if (err) {
return console.error(err);
}
for (let i = 0; i < folders.length; i++) {
fs.readdir(`./commands/${folders[i]}/`, (error, files) => {
if (error) {
return console.error(error);
}
files.forEach((file) => {
if (!file.endsWith('.js')) {
return;
}
const command = require(`./commands/${folders[i]}/${file}`);
client.commands.set(command.name, command);
});
});
}
});
client.once('ready', () => {
client.user.setPresence({ activity: { name: 'attraper Neferti' } });
const cron = require('node-cron');
cron.schedule('*/10 * * * *', () => {
let status = fs.readFileSync('./resources/bot/status.json');
status = JSON.parse(status);
status = Object.values(status);
const random = Math.floor((Math.random() * status.length) + 1) - 1;
client.user.setPresence({ activity: { name: status[random].text } });
});
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
}
catch (e) {
console.log(e);
message.reply('Désolé, cette commande n\'existe pas.');
}
});
client.login(token);