forked from lucid-eleven/nft-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
68 lines (55 loc) · 1.94 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require('dotenv').config()
const express = require('express')
const app = express()
const port = process.env.PORT || 5000;
const fs = require('fs');
const { prefix } = require('./config.json');
const Discord = require('discord.js');
const client = new Discord.Client();
client.commands = new Discord.Collection();
client.cronjobs = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
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);
}
const cronFiles = fs.readdirSync('./cronjobs').filter(file => file.endsWith('.js'));
for (const file of cronFiles) {
const job = require(`./cronjobs/${file}`);
// set a new item in the Collection
// with the key as the job name and the value as the exported module
if (job.enabled) {
console.log(`enabling ${job.description}`)
client.cronjobs.set(job.name, job);
}
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.cronjobs.forEach((value, key) => {
setInterval(function() {
value.execute(client);
}, value.interval);
});
})
client.on('message', msg => {
if (!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).trim().split(' ');
const commandName = args.shift().toLowerCase();
if (!client.commands.has(commandName)) return;
const command = client.commands.get(commandName);
try {
command.execute(msg, args);
} catch (error) {
console.error(error);
msg.reply('there was an error trying to execute that command!');
}
})
client.login(process.env.DISCORD_BOT_TOKEN);
app.get('/', (req, res) => {
res.send('The bot is running')
})
app.listen(port, () => {
console.log(`Discord Bot app listening at http://localhost:${port}`)
})