141 lines
1.6 KiB
JavaScript
141 lines
1.6 KiB
JavaScript
const {
|
|
Client,
|
|
GatewayIntentBits,
|
|
Collection,
|
|
Partials
|
|
} = require("discord.js");
|
|
|
|
const {
|
|
MongoClient
|
|
} = require("mongodb");
|
|
|
|
const fs = require("node:fs");
|
|
|
|
require("dotenv").config();
|
|
|
|
|
|
/*
|
|
* MONGODB
|
|
*/
|
|
|
|
const mClient =
|
|
new MongoClient(
|
|
process.env.M_URI
|
|
);
|
|
|
|
exports.mClient =
|
|
mClient;
|
|
|
|
|
|
/*
|
|
* DISCORD CLIENT
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
/*
|
|
* COLLECTIONS
|
|
*/
|
|
|
|
client.commands =
|
|
new Collection();
|
|
|
|
client.legacyCommands =
|
|
new Collection();
|
|
|
|
client.aliases =
|
|
new Collection();
|
|
|
|
client.buttons =
|
|
new Collection();
|
|
|
|
client.selectMenus =
|
|
new Collection();
|
|
|
|
client.modals =
|
|
new Collection();
|
|
|
|
|
|
/*
|
|
* START APPLICATION
|
|
*/
|
|
|
|
async function start() {
|
|
try {
|
|
|
|
/*
|
|
* Connect Mongo first.
|
|
*/
|
|
|
|
await mClient.connect();
|
|
|
|
console.log(
|
|
"MongoDB connected"
|
|
);
|
|
|
|
|
|
/*
|
|
* Load handlers.
|
|
*/
|
|
|
|
const handlerFiles =
|
|
fs.readdirSync(
|
|
"./handlers"
|
|
);
|
|
|
|
|
|
for (
|
|
const handler
|
|
of handlerFiles
|
|
) {
|
|
require(
|
|
`./handlers/${handler}`
|
|
)(client);
|
|
}
|
|
|
|
|
|
/*
|
|
* Login Discord.
|
|
*/
|
|
|
|
await client.login(
|
|
process.env.D_TOKEN
|
|
);
|
|
|
|
} catch (error) {
|
|
console.error(
|
|
"Failed to start ShaiBot:",
|
|
error
|
|
);
|
|
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
|
|
start(); |