mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 13:14:58 +05:00
74 lines
No EOL
2.4 KiB
JavaScript
74 lines
No EOL
2.4 KiB
JavaScript
require("./helpers/extenders");
|
|
|
|
const util = require("util"),
|
|
fs = require("fs"),
|
|
readdir = util.promisify(fs.readdir),
|
|
mongoose = require("mongoose"),
|
|
{ Intents } = require("discord.js");
|
|
|
|
// Load JaBa class
|
|
const JaBa = require("./base/JaBa");
|
|
const client = new JaBa({
|
|
intents: [
|
|
Intents.FLAGS.GUILDS,
|
|
Intents.FLAGS.GUILD_MEMBERS,
|
|
Intents.FLAGS.GUILD_BANS,
|
|
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
|
|
Intents.FLAGS.GUILD_INVITES,
|
|
Intents.FLAGS.GUILD_VOICE_STATES,
|
|
Intents.FLAGS.GUILD_PRESENCES,
|
|
Intents.FLAGS.GUILD_MESSAGES,
|
|
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
|
|
Intents.FLAGS.GUILD_MESSAGE_TYPING,
|
|
Intents.FLAGS.DIRECT_MESSAGES,
|
|
],
|
|
partials: ["CHANNEL"]
|
|
});
|
|
|
|
const init = async () => {
|
|
const directories = await readdir("./commands/");
|
|
client.logger.log(`Loading a total of ${directories.length} categories.`, "log");
|
|
directories.forEach(async (dir) => {
|
|
const commands = await readdir(`./commands/${dir}/`);
|
|
commands.filter((cmd) => cmd.split(".").pop() === "js").forEach((cmd) => {
|
|
const response = client.loadCommand(`./commands/${dir}`, cmd);
|
|
if (response) client.logger.log(response, "error");
|
|
});
|
|
});
|
|
|
|
const evtFiles = await readdir("./events/");
|
|
client.logger.log(`Loading a total of ${evtFiles.length} events.`, "log");
|
|
evtFiles.forEach((file) => {
|
|
const eventName = file.split(".")[0];
|
|
client.logger.log(`Loading Event: ${eventName}`);
|
|
const event = new(require(`./events/${file}`))(client);
|
|
client.on(eventName, (...args) => event.run(...args));
|
|
delete require.cache[require.resolve(`./events/${file}`)];
|
|
});
|
|
|
|
client.login(client.config.token);
|
|
|
|
mongoose.connect(client.config.mongoDB, {
|
|
useNewUrlParser: true,
|
|
useUnifiedTopology: true
|
|
}).then(() => {
|
|
client.logger.log("Connected to the Mongodb database.", "log");
|
|
}).catch((err) => {
|
|
client.logger.log(`Unable to connect to the Mongodb database. Error: ${err}`, "error");
|
|
});
|
|
|
|
const languages = require("./helpers/languages");
|
|
client.translations = await languages();
|
|
|
|
const autoUpdateDocs = require("./helpers/autoUpdateDocs");
|
|
autoUpdateDocs.update(client);
|
|
};
|
|
|
|
init();
|
|
|
|
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"));
|
|
|
|
process.on("unhandledRejection", (err) => console.error(err)); |