-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (62 loc) · 2.25 KB
/
index.js
File metadata and controls
67 lines (62 loc) · 2.25 KB
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
// require all the things
const Discord = require('discord.js');
const fs = require('fs').promises;
const Josh = require('josh');
const provider = require('@josh-providers/sqlite');
require('dotenv').config();
// make a client
const client = new Discord.Client({ ws: { intents: Discord.Intents.NON_PRIVILEGED } });
// config and stuff
client.config = require('./config.js');
require('./modules/functions.js')(client);
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
// db stuff
client.settings = new Josh({
name: 'settings',
provider,
serializer: (data, key, path) => {
if (!path) data = {
...data,
logChannel: data.logChannel ? data.logChannel.id : null,
modRole: data.modRole ? data.modRole.id : null,
adminRole: data.adminRole ? data.adminRole.id : null
};
if (['logChannel', 'adminRole', 'modRole'].includes(path)) data = data ? data.id : null;
return data;
}
,
deserializer: (data, guild) => {
return {
...data,
logChannel: data.logChannel ? client.guilds.cache.get(guild).channels.cache.get(data.logChannel) : null,
modRole: data.modRole ? client.guilds.cache.get(guild).roles.cache.get(data.modRole) : null,
adminRole: data.adminRole ? client.guilds.cache.get(guild).roles.cache.get(data.adminRole) : null
};
},
});
client.internal = new Josh({
name: 'internal',
provider,
});
(async () => {
let commands = await fs.readdir('./commands');
console.log(`Loading ${commands.length} commands.`);
let done = 0;
commands.forEach(cmd => {
if (!cmd.endsWith('.js')) return;
let r = client.loadCommand(cmd);
if (!r) done++;
});
console.log(`Successfully loaded ${done}/${commands.length} command${commands.length !== 1 ? 's' : ''}.`);
let events = await fs.readdir('./events');
console.log(`Loading ${events.length} events.`);
done = 0;
events.forEach(evt => {
if (!evt.endsWith('.js')) return;
let r = client.loadEvent(evt);
if (!r) done++;
});
console.log(`Successfully loaded ${done}/${events.length} event${events.length !== 1 ? 's' : ''}.`);
client.login(process.env.TOKEN);
})();