forked from KSJaay/Alita
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
63 lines (53 loc) · 2.01 KB
/
app.js
File metadata and controls
63 lines (53 loc) · 2.01 KB
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
const Discord = require("discord.js");
const config = require("./config.json"),
fs = require("fs"),
util = require("util"),
readdir = util.promisify(fs.readdir),
mongoose = require("mongoose");
const client = new Discord.Client();
client.events = new Discord.Collection();
client.commands = new Discord.Collection();
client.data = require("./database/MongoDB.js");
client.logger = require("./Modules/Logger.js");
client.tools = require("./Modules/Tools.js");
async function startUp(){
//Starting all events
const eventFiles = fs.readdirSync('./events/').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
const eventName = file.split(".")[0];
client.logger.event(`Loading Event - ${eventName}`);
client.on(eventName, event.bind(null, client));
}
//Load all the commands
let folders = await readdir("./commands/");
folders.forEach(direct =>{
const commandFiles = fs.readdirSync('./commands/' + direct + "/").filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${direct}/${file}`);
client.commands.set(command.name, command);
}
})
//Connect to mongoose database
mongoose.connect(config.mongoDB, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
//If it connects log the following
client.logger.log("Connected to the Mongodb database.", "log");
}).catch((err) => {
//If it doesn't connect log the following
client.logger.log("Unable to connect to the Mongodb database. Error:"+err, "error");
});
client.login(config.token)
}
startUp();
// if there are errors, log them
client.on("disconnect", () => client.logger.log("Bot is disconnecting...", "warn"))
.on("reconnecting", () => client.logger.log("Bot reconnecting...", "log"))
.on("error", (e) => client.logger.log(e, "error"))
.on("warn", (info) => client.logger.log(info, "warn"));
//For any unhandled errors
process.on("unhandledRejection", (err) => {
console.error(err);
});