-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (65 loc) · 2.52 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
69
70
71
72
73
74
75
76
77
78
79
80
const { Client, Collection } = require('discord.js');
const { Scraper } = require('./scraper.js');
const { PREFIX, BOT_TOKEN } = require('./config.js');
const { Player } = require("discord-player");
const fs = require('fs');
const chalk = require('chalk');
const client = new Client({ disableEveryone: true});
const player = new Player(client);
client.commands = new Collection();
client.player = player;
chalk.enabled = true;
fs.readdirSync('./commands').forEach(dirs => {
const commands = fs.readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js'));
for (const file of commands) {
const command = require(`./commands/${dirs}/${file}`);
client.commands.set(command.name.toLowerCase(), command);
}
})
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
console.log(chalk.green(`(MAIN): Loading event ${file}`));
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.player.on(event.name, (...args) => event.execute(...args));
}
}
/////////////////////////////////////////////////////////////////////
// Console logging
client.on('warn', console.warn);
client.on('error', console.error);
client.on('ready', () => {
console.log(chalk.green('(MAIN): Primed and ready!'))
client.user.setActivity('Baju', { type: 'LISTENING'})
try {
(async() => {
Scraper();
}
)();
} catch (error) {
console.log(chalk.red(error));
}
});
client.on('disconnect', () => console.log('Disconnected, will reconnect...'));
client.on('reconnecting', () => console.log('I am reconnecting now!'));
client.on('message', async msg => {
// Prevent the bot from responding to itself, other bots or to commands without the correct prefix
if (msg.author.bot)
return null;
if (!msg.content.startsWith(PREFIX))
return null;
const args = msg.content.slice(PREFIX.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
try {
const cmd = client.commands.get(command) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(command));
if (cmd) {
cmd.execute(msg, client, args);
}
} catch (error) {
console.error(chalk.red("(MAIN) " + error));
msg.reply('There was an error trying to run that command.');
}
});
client.login(BOT_TOKEN);