This repository was archived by the owner on Aug 18, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
70 lines (53 loc) · 2.33 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
import { Client, GatewayIntentBits, Events } from 'discord.js';
import dotenv from 'dotenv';
import { getTopLevel } from './lib/db.js';
import lightercolors from 'lighter-colors';
import { verbose } from './lib/flags.js';
dotenv.config();
const cli = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
// Ready Event
cli.once(Events.ClientReady, () => console.log(`[info]: Connected to Discord!\n\tGuild Count: ${cli.guilds.cache.size}\n\tMy ID: ${cli.user.id}`.green))
// Text Command Indexer ******************************************************
import { indexTextCommands } from './indexers/textIndexer.js';
await indexTextCommands();
// Slash Command Indexer *****************************************************
import { indexSlashCommands } from './indexers/slashIndexer.js';
await indexSlashCommands();
// Push Commands to Discord API **********************************************
import { pushCommands } from './lib/pushCommands.js';
await pushCommands();
// Message handler ***********************************************************
import { commands } from './indexers/textIndexer.js';
import { handleMessage } from './handlers/messageHandler.js';
cli.on(Events.MessageCreate, async message => {
await handleMessage(message, cli, commands);
})
// Interaction Handler ********************************************************
import { handleInteraction } from './handlers/interactionHandler.js';
import { slashCommands } from './indexers/slashIndexer.js';
cli.on(Events.InteractionCreate, async interaction => {
await handleInteraction(interaction, cli, slashCommands);
})
// Other Events ***************************************************************
cli.on(Events.Error, (e) => console.log(colors.red(e)));
cli.on(Events.Warn, (e) => console.log(colors.yellow(e)));
if (verbose) {
cli.on(Events.Debug, (e) => console.log(colors.magenta(e)));
}
cli.on(Events.Invalidated, () => {
console.log(
'Session invalidated! Shutting down, Reboot will be required manually.'.bgRed,
);
cli.destroy();
process.exit(3);
});
// Login *********************************************************************
await cli.login(process.env.DISCORD_TOKEN);
cli.user.setStatus(await getTopLevel("status"));