-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
56 lines (44 loc) · 1.19 KB
/
main.ts
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
import { Client, REST, Routes } from "discord.js";
import { z } from "zod";
import * as modules from "./modules";
import { config } from "dotenv";
const envSchema = z.object({
BOT_TOKEN: z.string(),
BOT_ID: z.string(),
GUILD_ID: z.string(),
OBSERVER_CHANNEL_ID: z.string(),
});
config();
export type Env = z.infer<typeof envSchema>;
const env = envSchema.parse(process.env);
process.env.TZ = "Asia/Tokyo";
const client = new Client({
intents: [
"Guilds",
"GuildVoiceStates",
"GuildMessages",
"GuildMembers",
"MessageContent",
],
});
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);