-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (62 loc) · 2.28 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
import { Client, Collection, GatewayIntentBits, Partials, ActivityType } from "discord.js";
import { listener } from "./events/musicPlayer.js";
import { Player } from "discord-player";
import { readdirSync } from "node:fs";
import { join } from "node:path";
import "dotenv/config";
const clientOptions = {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildVoiceStates,
],
presence: {
status: "online",
activities: [
{
name: "Taking care of you",
type: ActivityType.Playing,
},
],
},
partials: [Partials.Channel],
};
const client = new Client(clientOptions);
// Music player
const player = Player.singleton(client);
listener(player);
// Events
const eventsPath = join(process.cwd(), "events");
const eventFiles = readdirSync(eventsPath).filter((file) => file.endsWith(".js") || file.endsWith(".ts"));
for (const file of eventFiles) {
const url = `file:///${join(eventsPath, file)}`;
const eventFile = await import(url);
if (eventFile.once) {
client.once(eventFile.name, (...args) => eventFile.execute(...args));
} else if (eventFile.once === false) {
client.on(eventFile.name, (...args) => eventFile.execute(...args));
}
}
// Commands
client.commands = new Collection();
client.cooldowns = new Collection();
const foldersPath = join(process.cwd(), "commands");
const commandFolders = readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = join(foldersPath, folder);
const commandFiles = readdirSync(commandsPath).filter((file) => file.endsWith(".js") || file.endsWith(".ts"));
for (const file of commandFiles) {
const url = `file:///${join(commandsPath, file)}`;
const commandFile = await import(url);
if (commandFile.data && commandFile.execute) {
client.commands.set(commandFile.data.name, commandFile);
} else {
console.log(`[WARNING] The command at ${url} is missing a required "data" or "execute" property.`);
}
}
}
client.login(process.env.CLIENT_TOKEN);
export default client;