forked from AndrykVP/discord-raffle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (43 loc) · 1.46 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
require('dotenv').config()
const fs = require('fs');
const { prefix } = require('./config.json');
const trivialdb = require('trivialdb');
const ns = trivialdb.ns('mr-raffle');
const db = ns.db('raffle')
db.loading.then(() =>
{
console.log('DB loaded');
});
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const Discord = require('discord.js');
const token = process.env.BOT_TOKEN;
// Initialize Discord Bot with Custom Commands
const client = new Discord.Client();
client.commands = new Discord.Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// Set a new item in the Collection
// with the key as the command name and the value as the exported module
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Bot is running');
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
var args = message.content.slice(prefix.length).split(/ +/);
var command = args.shift().toLowerCase();
if (!client.commands.has(command)) {
message.channel.send('Sorry, I do not recognize that command.')
return
};
try {
client.commands.get(command).execute(message, args);
}
catch (error) {
console.error(error);
message.channel.send('Oops! There was an error trying to execute that command!');
}
});
// Login to Discord with bot's token
client.login(token);