-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.js
114 lines (101 loc) · 3.67 KB
/
index.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DEPENDENCIES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
console.log("[Loading Dependencies]");
const defaultConfig = require("./defaultConfig.json");
const fs = require("fs");
const keepAlive = require("./server.js");
const process = require("process");
require("dotenv").config();
const { Client, Collection, Intents, MessageEmbed } = require("discord.js");
// Initialize bot client and the intents it's needed.
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.DIRECT_MESSAGES,
],
partials: [ "CHANNEL" ],
});
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~VARIABLES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Variable to temporarily store bot configuration, blocked users id, and active threads so it can be accessed without invoking database commands.
const cmdDataList = [];
const config = {};
const blockList = [];
const tagList = {};
const threadList = [];
// Command cooldowns
client.cooldowns = new Collection();
// Variable to store dependencies, functions and variables to be easily accessed across files.
const param = {
blockList,
client,
cmdDataList,
Collection,
config,
defaultConfig,
MessageEmbed,
running: false,
tagList,
threadList,
timestamp: "",
};
// Filtering command, event, function, and locale files from their respective folders.
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js"));
const functionFiles = fs.readdirSync("./functions").filter(file => file.endsWith(".js"));
const localeFiles = fs.readdirSync("./locale").filter(file => file.endsWith(".js"));
// Store language information in param client.
param["locale"] = {};
for (const file of localeFiles) {
const locale = require(`./locale/${file}`);
param.locale[locale.name] = locale;
console.log(`> Stored ${locale.name} language to memory.`);
}
// Store commands code in bot client.
client.commands = new Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// Cycling through locale languages and store command in each language.
Object.keys(param.locale).forEach(key => {
const currentLang = param.locale[key];
const localeName = currentLang.commands[command.name].name;
cmdDataList.push({
name: localeName,
language: key,
id: "-"
});
client.commands.set(localeName, command);
console.log(`> Stored "${localeName}"[${command.name}] command to memory.`);
});
}
// Store functions code in param variable.
for (const file of functionFiles) {
const fn = require(`./functions/${file}`);
param[fn.name] = fn;
console.log(`> Stored ${fn.name} function to memory.`);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EVENT HANDLER~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Handling Discord Events.
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.disabled) continue;
if (event.once) {
client.once(event.name, async (...args) => await event.execute(param, ...args));
}
else {
client.on(event.name, async (...args) => await event.execute(param, ...args));
}
}
/* *
client
.on("debug", console.log)
.on("warn", console.log);
/* */
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~LOGIN~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
keepAlive();
client.login(process.env.TOKEN);
require("https").createServer().listen();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~