-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
79 lines (67 loc) · 1.96 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
require('dotenv').config();
const loggerInit = require('./utils/logger.js');
loggerInit();
log.time('startup');
log.info('Starting Cutiebot!');
const {
Client,
Collection,
GatewayIntentBits,
Partials,
} = require('discord.js');
const token = process.env.DISCORD_TOKEN;
if (!token) {
log.error(
'Token not provided. Set the DISCORD_TOKEN environment variable and restart.'
);
process.exit(1);
}
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
],
});
const fs = require('fs');
const chalk = require('chalk');
client.commands = new Collection();
const commandFiles = fs
.readdirSync('./commands')
.filter((file) => file.endsWith('.js'));
log.info(`Loading a total of ${chalk.bold(commandFiles.length)} commands.`);
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
log.debug(`Loaded ${chalk.bold(command.data.name)} command.`);
}
const eventFiles = fs
.readdirSync('./events/')
.filter((file) => file.endsWith('.js'));
log.info(`Loading a total of ${chalk.bold(eventFiles.length)} events.`);
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
log.debug(`Loaded ${chalk.bold(event.name)} event.`);
}
process.on('unhandledRejection', (error) => {
log.error('Uncaught Promise Rejection');
log.error(error);
});
client
.on('disconnect', () => log.warn('Bot is disconnecting...'))
.on('reconnecting', () => log.info('Bot reconnecting...'))
.on('debug', (debug) => log.debug(debug))
.on('error', (e) => {
log.error(e);
console.trace();
})
.on('warn', (info) => log.warn(info));
client.login(token);