-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (75 loc) · 2.25 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
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const fs = require('fs');
const config = require('./config.js');
require('dotenv')
.config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.MessageContent
],
});
client.config = config;
client.buttons = new Collection();
client.commands = new Collection();
client.messageCommands = new Collection();
client.stringSelects = new Collection();
client.modals = new Collection();
client.suggestCooldown = new Collection();
client.marketplaceCooldown = new Collection();
client.voteAppealCollection = new Collection();
// Debug
if (config.debug) {
client.on('debug', (e) => console.info(e));
}
// Register events
registerEvent();
// Register interactions
registerInteraction('buttons', client.buttons);
registerInteraction('commands', client.commands);
registerInteraction('messageCommands', client.messageCommands);
registerInteraction('stringSelects', client.stringSelects);
registerInteraction('modals', client.modals);
client.login(process.env.DISCORD_TOKEN);
function registerEvent() {
const folderName = 'events';
createDirectory(folderName);
const files = readFiles(folderName);
// Save interaction into client
for (const file of files) {
const eventName = file.split('.')[0];
const event = require(`./${folderName}/${file}`);
client.on(eventName, event.bind(null, client));
console.log(`Binded event ${eventName}`);
}
}
function registerInteraction(folderName, collection) {
createDirectory(folderName);
const files = readFiles(folderName);
// Save interaction into client
for (const file of files) {
const interactionName = file.split('.')[0];
const interaction = require(`./${folderName}/${file}`);
collection.set(interactionName, interaction);
console.log(`Loaded ${folderName} ${interactionName}`);
}
}
/**
* Create directory if it doesn't exist
*/
function createDirectory(directory) {
if (!fs.existsSync(`./${directory}`)) {
fs.mkdirSync(`./${directory}`);
}
}
/**
* Find all the files in directory
*/
function readFiles(directory) {
return fs
.readdirSync(`./${directory}`)
.filter((file) => file.endsWith('.js'));
}