95 lines
2.2 KiB
JavaScript
95 lines
2.2 KiB
JavaScript
const {
|
|
Client,
|
|
GatewayIntentBits,
|
|
Collection,
|
|
Partials
|
|
} = require("discord.js");
|
|
|
|
const { MongoClient } = require("mongodb");
|
|
const fs = require("node:fs");
|
|
|
|
require("dotenv").config();
|
|
|
|
const mClient = new MongoClient(
|
|
process.env.M_URI
|
|
);
|
|
|
|
exports.mClient = mClient;
|
|
|
|
const client = new Client({
|
|
intents: [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMembers,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.GuildPresences,
|
|
GatewayIntentBits.GuildMessageReactions,
|
|
GatewayIntentBits.GuildVoiceStates,
|
|
GatewayIntentBits.DirectMessages,
|
|
GatewayIntentBits.MessageContent
|
|
],
|
|
partials: [
|
|
Partials.Channel,
|
|
Partials.Message,
|
|
Partials.User,
|
|
Partials.GuildMember,
|
|
Partials.Reaction
|
|
]
|
|
});
|
|
|
|
exports.client = client;
|
|
|
|
client.commands = new Collection();
|
|
client.legacyCommands = new Collection();
|
|
client.aliases = new Collection();
|
|
client.buttons = new Collection();
|
|
client.selectMenus = new Collection();
|
|
client.modals = new Collection();
|
|
|
|
async function start() {
|
|
try {
|
|
await mClient.connect();
|
|
console.log("MongoDB connected");
|
|
|
|
const {
|
|
ensureCookieIndexes
|
|
} = require("./utils/cookieEconomy");
|
|
const {
|
|
ensureProfileSystem
|
|
} = require("./utils/profileSystem");
|
|
const {
|
|
ensureInteractionSessionIndexes
|
|
} = require("./utils/interactionSession");
|
|
const {
|
|
ensureBankruptcyIndexes
|
|
} = require("./utils/bankruptcy");
|
|
|
|
await Promise.all([
|
|
ensureCookieIndexes(),
|
|
ensureProfileSystem(),
|
|
ensureInteractionSessionIndexes(),
|
|
ensureBankruptcyIndexes()
|
|
]);
|
|
|
|
console.log("Database indexes initialized");
|
|
|
|
const handlerFiles = fs.readdirSync("./handlers");
|
|
|
|
for (const handler of handlerFiles) {
|
|
require(`./handlers/${handler}`)(client);
|
|
}
|
|
|
|
await client.login(
|
|
process.env.D_TOKEN
|
|
);
|
|
} catch (error) {
|
|
console.error(
|
|
"Failed to start ShaiBot:",
|
|
error
|
|
);
|
|
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
start();
|