-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbootstrap.js
76 lines (65 loc) · 2.02 KB
/
bootstrap.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
const users = new Map();
const {
Client,
Collection,
ActivityType,
GatewayIntentBits,
Events,
} = require('discord.js');
let config;
try {
config = require('./config/config.json');
} catch {
console.error(
//@note: just in case user forget to rename the file.
`Missing config file, make sure to remove "EXAMPLE" from config file!\nExitting!`,
);
return;
}
const commandHandler = require('./src/utils/commandHandler');
const eventHandler = require('./src/utils/eventHandler');
const componentHandler = require('./src/utils/componentHandler');
const client = new Client({
intents: Object.values(GatewayIntentBits).reduce(
(acc, intent) => acc | intent, //@note: found on stackoverflow, automatically getting every bot intent - in cost of performance.
0,
),
});
const logHandler = require('./src/utils/logHandler');
client.commands = new Collection();
client.cooldowns = new Collection();
client.once(Events.ClientReady, async () => {
logHandler.initialize(client);
//@note: just in case not really needed
if (client.user.bot == false) {
console.log('Token is incorrect!');
}
console.log(`Logged in as ${client.user.displayName}`);
//@note: sets bot's rich presence status
client.user.setPresence({
activities: [
{
name: `Discord JS Bot Template - https://github.com/NoSkill33`,
type: ActivityType.Custom,
},
],
status: 'online',
});
//@note: initlaize handlers
await commandHandler.loadCommands(client).catch(console.error);
await eventHandler.loadEvents(client).catch(console.error);
await componentHandler.loadComponents(client).catch(console.error);
});
client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isCommand()) {
await commandHandler
.synchronizeCommands(interaction, client)
.catch(console.error);
} else {
await componentHandler
.synchronizeComponent(interaction, client)
.catch(console.error);
}
});
module.exports = client;
client.login(config.token).catch(console.error);