-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (36 loc) · 1.09 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
import express from 'express';
import Discord from 'discord.js';
import routes from './routes.js';
import botCommands from './commands/index.js';
import config from './config.js';
// Setting up the server
const app = express();
app.use(routes);
// Setting up bot's commands
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
Object.keys(botCommands).map(key => {
bot.commands.set(botCommands[key].name, botCommands[key]);
})
// Logging the bot in
bot.login(config.discordBotToken);
bot.on('ready', () => {
console.info(`>> Logged in as ${bot.user.tag}!`);
})
// Listen to messages at Discord text channel and bind them to respective commands
bot.on('message', msg => {
const command = msg.content.split(/ +/).shift().toLowerCase();
if(!bot.commands.has(command)){
return;
}
try {
bot.commands.get(command).execute(msg);
}
catch (error) {
console.error(error);
msg.reply('Ocorreu um erro ao executar o comando!');
}
})
app.listen(config.port, () => {
console.log('>> Server running on port ' + process.env.PORT);
})