-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
93 lines (85 loc) · 2.58 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
87
88
89
90
91
92
93
const {
Client,
GatewayIntentBits,
Collection,
Partials,
EmbedBuilder,
} = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
],
partials: [Partials.Channel],
ws: {
properties: {
$os: "Untitled OS",
$browser: "Untitled Browser",
$device: "K8s on Proxmox VE 6.4 in Sibainu",
},
},
});
const fs = require("fs");
const config = require("./config.js");
const functions = { timeUtils: require("./lib/timeUtils.js"),logUtils: require("./lib/logUtils.js") };
client.conf = config;
client.func = functions;
client.fs = fs;
const cmdH = require(`./lib/commandUtils.js`);
client.commands = new Collection(); // Add this line to define the client.commands object
cmdH.handling(client, fs, Collection, config);
// イベントハンドリング
const eventFiles = fs
.readdirSync("./events")
.filter((file) => file.endsWith(".js"));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
try {
client.once(event.name, (...args) => event.execute(...args, client));
} catch (error) {
console.error(
`\u001b[31m[${functions.timeUtils.timeToJST(Date.now(), true)}]\u001b[0m\n`,
error
);
}
} else {
try {
client.on(event.name, (...args) => event.execute(...args, client));
} catch (error) {
console.error(
`\u001b[31m[${functions.timeUtils.timeToJST(Date.now(), true)}]\u001b[0m\n`,
error
);
}
}
}
client.login(config.token);
// エラー処理 (これ入れないとエラーで落ちる。本当は良くないかもしれない)
process.on("uncaughtException", (error) => {
console.error(`[${functions.timeUtils.timeToJST(Date.now(), true)}] ${error.stack}`);
const embed = new EmbedBuilder()
.setTitle("ERROR - uncaughtException")
.setDescription("```\n" + error.stack + "\n```")
.setColor(config.color.e)
.setTimestamp();
client.channels
.fetch(config.logch.error)
.then((c) => c.send({ embeds: [embed] }));
});
process.on("unhandledRejection", (reason, promise) => {
console.error(
`\u001b[31m[${functions.timeUtils.timeToJST(Date.now(), true)}] ${reason}\u001b[0m\n`,
promise
);
const embed = new EmbedBuilder()
.setTitle("ERROR - unhandledRejection")
.setDescription("```\n" + reason + "\n```")
.setColor(config.color.e)
.setTimestamp();
client.channels
.fetch(config.logch.error)
.then((c) => c.send({ embeds: [embed] }));
});