-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
executable file
·49 lines (41 loc) · 1.32 KB
/
bot.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
const fs = require('fs');
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
bot.config = require('./config.json');
bot.activeConnection = null;
bot.music = {
dispatcher: null,
queue: []
};
bot.timeouts = {
disconnect: null
}
// read and set up commands
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
}
bot.on('ready', () => {
console.log(`Logged in as ${bot.user.tag}!`);
});
bot.on('message', msg => {
if (!msg.content.startsWith(bot.config.prefix) || msg.author.bot) {
// ignore messages without command prefix and from bots
return;
}
const args = msg.content.slice(bot.config.prefix.length).split(/ +/); // temp solution, add suppot for ""
const command = args.shift().toLowerCase();
if (!bot.commands.has(command)) {
msg.channel.send(`Unknown command. Try ${bot.config.prefix}help`);
return;
}
try {
bot.commands.get(command).execute(msg, args);
} catch (error) {
console.error(error);
msg.channel.send(`There was an error trying to execute "${msg.content}"`);
}
});
bot.login(bot.config.token);