-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (69 loc) · 2.86 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
import process from "process";
import {config} from "dotenv";
config();
import winston from "winston";
import moment from "moment";
import {Client, Intents, Collection} from "discord.js";
import {
getCommandFiles,
logger,
custom_logger_levels,
startEvents
} from "./utils/jerryUtils.js";
if (process.env.npm_lifecycle_event !== "main") {
logger.add(new winston.transports.Console({
format: winston.format.combine(
// colorizzing the level breaks the message when using level.toUpperCase(). See: https://github.com/winstonjs/winston/issues/1345
winston.format.colorize({message: true, colors: custom_logger_levels.colors}),
winston.format.printf(({level, message}) => {
return `[${moment().format("HH:mm:ss.SSS")}] [${level.toUpperCase()}/${message}`;
})
)
}));
}
console.log(`>>>>> The bot was started!${process.env.npm_lifecycle_event ? ` (npm run ${process.env.npm_lifecycle_event})` : ""}`);
logger.append("info", "index.js", `>>>>> [Startup] The bot was started!${process.env.npm_lifecycle_event ? ` (npm run ${process.env.npm_lifecycle_event})` : ""}`);
const client = new Client({
intents: [
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MESSAGE_TYPING,
Intents.FLAGS.GUILD_INVITES,
Intents.FLAGS.GUILD_BANS,
]
});
// Main
(async () => {
// Getting commands
console.log("Getting command files...");
logger.append("debug", "index.js", "[Startup] Getting command files...");
const suffix = ".js";
const command_files = await getCommandFiles("./commands", suffix);
console.log(`Queued ${command_files.commands.length} + ${command_files.exclusive.length} (${command_files.commands.length + command_files.exclusive.length}) files, ignored ${command_files.ignored.length} files, skipped ${command_files.skipped.length} files:`);
console.log(command_files);
const commands = {
commands: [],
exclusive: []
};
client.commands = new Collection();
for (const file of command_files.commands) {
const module = await import(file);
const command = module.default;
commands.commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
}
for (const file of command_files.exclusive) {
const module = await import(file);
const command = module.default;
commands.exclusive.push(command.data.toJSON());
client.commands.set(command.data.name, command);
}
// Getting events
await startEvents(client, commands);
client.login(process.env.DISCORD_BOT_TOKEN_JERRY);
})();