-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.ts
More file actions
61 lines (49 loc) · 1.48 KB
/
main.ts
File metadata and controls
61 lines (49 loc) · 1.48 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
import { Client, REST, Routes, Partials } from "discord.js";
import * as v from "valibot";
import * as modules from "./modules";
import { config } from "dotenv";
const envSchema = v.object({
BOT_TOKEN: v.string(),
BOT_ID: v.string(),
GUILD_ID: v.string(),
OBSERVER_CHANNEL_ID: v.string(),
REACTION_FORWARDER_CHANNEL_ID: v.string(),
REACTION_FORWARDER_REACTIONS: v.string(),
REACTION_FORWARDER_THRESHOLD: v.pipe(v.string(), v.transform(Number), v.integer()),
});
config();
export type Env = v.InferOutput<typeof envSchema>;
const env = v.parse(envSchema, process.env);
process.env.TZ = "Asia/Tokyo";
const client = new Client({
intents: [
"Guilds",
"GuildVoiceStates",
"GuildMessages",
"GuildMembers",
"MessageContent",
"GuildMessageReactions",
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});
client.once("ready", () => {
console.log(`Logged in as ${client.user?.tag}!`);
});
const commandsJsons = Object.values(modules).flatMap((Module) => {
const module = new Module(client, env);
module.init();
return module.command();
});
const rest = new REST({ version: "10" }).setToken(env.BOT_TOKEN);
(async () => {
try {
console.log("Started refreshing application (/) commands.");
await rest.put(Routes.applicationCommands(env.BOT_ID), {
body: commandsJsons,
});
console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
})();
client.login(env.BOT_TOKEN);