-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
76 lines (69 loc) · 2.3 KB
/
index.ts
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
69
70
71
72
73
74
75
76
// Import packages from NPM
import DiscordJs, { Intents } from "discord.js";
import WOKCommands from "wokcommands";
import path from "path";
import chalk from "chalk";
import dotenv from "dotenv";
import { isDocker } from "./utils/util";
// import all environment variables from .env file
dotenv.config();
// Create a new Discord client
const client = new DiscordJs.Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
],
});
client.on("ready", async () => {
if (client.user) {
console.log(chalk.green(`Logged in as ${client.user.tag}!`));
if (isDocker())
console.log(chalk.blueBright(`Running in a Docker container!`));
console.log(
chalk.yellow.bold(`I am running version: ${process.env.VERSION}`)
);
}
const dbOptions = {
// These are the default values
keepAlive: true,
useNewUrlParser: true,
useUnifiedTopology: true,
};
// Set up the WOKCommands instance
const wok = new WOKCommands(client, {
commandDir: path.join(__dirname, "commands"),
featureDir: path.join(__dirname, "features"),
dbOptions,
typeScript: true,
mongoUri: String(process.env.MONGODB_URI),
disabledDefaultCommands: ["help", "language"],
botOwners: [
"603629606154666024",
],
}).setDefaultPrefix(String(process.env.BOT_DEFAULT_PREFIX));
// Set up the connection to the database
wok.on("databaseConnected", async () => {
console.log(chalk.green("Connected to the database"));
});
});
// Catch all errors that are not handled well and just dump to the console. THis will be changed later but for now it's fine.
client.on("error", console.error);
client.on("warn", (e) => console.warn(e));
process.on("unhandledRejection", (promise, reason) => {
console.error("Unhandled promise rejection:", promise, "\nreason", reason);
});
// Login to Discord with the bot token and display an error if it fails.
client.login(process.env.MAIN_TOKEN).catch((error) => {
console.log(
chalk.red.bold(`There was an error connecting to the Discord API`)
);
console.error(error);
process.exit(1);
});
// Exit gracefully and print the exit code.
process.on("exit", (code) => {
console.log("Now exiting...");
console.log(`Exited with status code: ${code}`);
});