Botanique/src/index.ts

79 lines
2.3 KiB
TypeScript
Raw Normal View History

import loadClient, { quit } from "./utils/client";
import loadEvents from "./events/loader";
import loadModals from "./modals/loader";
import loadButtons from "./buttons/loader";
import loadCommands from "./commands/loader";
import { logStart } from "./utils/misc";
/** Run the bot. */
const run = async () => {
console.log("Starting Botanique...");
// Load .env if not in prod
if (process.env.NODE_ENV !== "production") {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
(await import("dotenv")).config({ path: "./config/.env" });
}
// Client Discord.JS
const client_name = "Client";
await loadClient()
.then(async (client) => {
// Events Discord.JS
const events_name = "Events";
await loadEvents(client)
.then(() => console.log(logStart(events_name, true)))
.catch((err) => {
console.error(err);
throw logStart(events_name, false);
});
// Connect the bot to Discord.com
await client.login(client.config.token_discord);
// Modals Discord.JS
const modals_name = "Modals";
await loadModals(client)
.then(() => console.log(logStart(modals_name, true)))
.catch((err) => {
console.error(err);
throw logStart(modals_name, false);
});
// Buttons Discord.JS
const buttons_name = "Buttons";
await loadButtons(client)
.then(() => console.log(logStart(buttons_name, true)))
.catch((err) => {
console.error(err);
throw logStart(buttons_name, false);
});
// Commands Slash Discord.JS
const commands_name = "Commands";
await loadCommands(client)
.then(() => console.log(logStart(commands_name, true)))
.catch((err) => {
console.error(err);
throw logStart(commands_name, false);
});
console.log(logStart(client_name, true));
console.log(`Botanique "${client.user?.username}" v${client.config.version} started!`);
// ^C
process.on("SIGINT", () => quit(client));
// Container force closed
process.on("SIGTERM", () => quit(client));
})
.catch((err) => {
console.error(err);
throw logStart(client_name, false);
});
};
run().catch((error) => console.error(error));