-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
42 lines (35 loc) · 1.28 KB
/
app.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
import "dotenv/config";
import { Client, Collection, GatewayIntentBits } from "discord.js";
import { getCommands } from "./util/getCommands.js";
import { getEvents } from "./util/getEvents.js";
import { fileURLToPath } from "url";
import { dirname, join } from "node:path";
import storage from "node-persist";
import {strict as assert} from "assert";
await storage.init({
dir: "./db",
});
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Create a new client instance
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildScheduledEvents],
});
// Collect and setup commands
client.commands = new Collection();
const commands = await getCommands(join(__dirname, "commands"));
commands.forEach((command) => {
client.commands.set(command.data.name, command);
});
// Collect and setup events
const events = await getEvents(join(__dirname, "events"));
events.forEach((event) => {
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
});
// Log in to Discord with your client's token
assert(process.env.BOT_TOKEN, "BOT_TOKEN is not defined, please define it in .env file");
await client.login(process.env.BOT_TOKEN);