-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (90 loc) · 3.53 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
const { discordMessage, scriptMessage, warnMessage, errorMessage } = require('./src/functions/logger.js');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { deployCommands, deployDevCommands } = require('./deploy-commands.js');
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const { toFixed, generateID } = require('./src/functions/helper.js');
const config = require('./config.json');
const path = require('path');
const fs = require('fs');
async function start() {
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
],
});
client.commands = new Collection();
const foldersPath = path.join(__dirname, 'src/commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
warnMessage(`The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
deployCommands();
deployDevCommands();
await delay(3000);
client.once(Events.ClientReady, async () => {
global.uptime = toFixed(new Date().getTime() / 1000, 0);
global.client = client;
discordMessage(`Client Logged in as ${client.user.tag}`);
const scriptFiles = fs.readdirSync('./src/scripts').filter((file) => file.endsWith('.js'));
scriptMessage(`Found ${scriptFiles.length} scripts and running them all`);
var skipped = 0;
for (const file of scriptFiles) {
try {
if (file.toLowerCase().includes('disabled')) {
skipped++;
scriptMessage(`Skipped ${file} script`);
continue;
}
scriptMessage(`Started ${file} script`);
require(`./src/scripts/${file}`);
await delay(300);
} catch (error) {
skipped++;
var errorId = generateID(config.other.errorIdLength);
errorMessage(`Error ID: ${errorId}`);
errorMessage(error);
}
}
scriptMessage(`Started ${scriptFiles.length - skipped} script(s) and skipped ${skipped} script(s)`);
});
const eventsPath = path.join(__dirname, 'src/events');
const eventFiles = fs.readdirSync(eventsPath).filter((file) => file.endsWith('.js'));
scriptMessage(`Found ${eventFiles.length} event(s) and running them all`);
var skippedEvents = 0;
for (const file of eventFiles) {
try {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (file.toLowerCase().includes('disabled')) {
skippedEvents++;
scriptMessage(`Skipped ${file} event`);
continue;
}
client.on(event.name, (...args) => event.execute(...args));
await delay(300);
scriptMessage(`Started ${file} event`);
} catch (error) {
skippedEvents++;
var errorId = generateID(config.other.errorIdLength);
errorMessage(`Error ID: ${errorId}`);
errorMessage(error);
}
}
scriptMessage(`Started ${eventFiles.length - skippedEvents} event(s) and skipped ${skippedEvents} event(s)`);
client.login(config.discord.token);
}
start();