Tinasha-Bot/bot.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-08-20 14:29:07 +09:00
require("dotenv").config();
require("module-alias/register");
2024-03-17 13:58:37 +09:00
// register extenders
require("@helpers/extenders/Message");
require("@helpers/extenders/Guild");
require("@helpers/extenders/GuildChannel");
const { checkForUpdates } = require("@helpers/BotUtils");
const { initializeMongoose } = require("@src/database/mongoose");
2023-08-20 14:29:07 +09:00
const { BotClient } = require("@src/structures");
2024-03-17 13:58:37 +09:00
const { validateConfiguration } = require("@helpers/Validator");
2023-08-20 14:29:07 +09:00
2024-03-17 13:58:37 +09:00
validateConfiguration();
2023-08-20 14:29:07 +09:00
// initialize client
const client = new BotClient();
client.loadCommands("src/commands");
client.loadContexts("src/contexts");
client.loadEvents("src/events");
// find unhandled promise rejections
process.on("unhandledRejection", (err) => client.logger.error(`Unhandled exception`, err));
(async () => {
2024-03-17 13:58:37 +09:00
// check for updates
await checkForUpdates();
// start the dashboard
2023-08-20 14:29:07 +09:00
if (client.config.DASHBOARD.enabled) {
client.logger.log("Launching dashboard");
try {
const { launch } = require("@root/dashboard/app");
2024-03-17 13:58:37 +09:00
// let the dashboard initialize the database
2023-08-20 14:29:07 +09:00
await launch(client);
} catch (ex) {
client.logger.error("Failed to launch dashboard", ex);
}
2024-03-17 13:58:37 +09:00
} else {
// initialize the database
await initializeMongoose();
2023-08-20 14:29:07 +09:00
}
2024-03-17 13:58:37 +09:00
// start the client
2023-08-20 14:29:07 +09:00
await client.login(process.env.BOT_TOKEN);
})();