-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (47 loc) · 1.52 KB
/
index.js
File metadata and controls
53 lines (47 loc) · 1.52 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
require("dotenv").config();
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const fs = require("fs");
const path = require("path");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers,
],
});
// Load Commands
client.commands = new Collection();
const commandsPath = path.join(__dirname, "commands");
fs.readdirSync(commandsPath).forEach((file) => {
if (file.endsWith(".js")) {
const command = require(`./commands/${file}`);
console.log(command); // Log to debug the structure of the command file
if (command.data && command.data.name) {
client.commands.set(command.data.name, command);
} else {
console.error(`❌ Command missing 'data.name' in ${file}`);
}
}
});
// Function to Load Events
const handleEvents = () => {
const eventsPath = path.join(__dirname, "events");
fs.readdirSync(eventsPath).forEach((file) => {
if (file.endsWith(".js")) {
const event = require(`./events/${file}`);
const eventName = path.parse(file).name;
client.on(eventName, async (...args) => {
try {
await event(client, ...args);
} catch (error) {
console.error(`❌ Error in event: ${eventName}`, error);
}
});
}
});
};
handleEvents(); // Load all events
// Login the bot
client.login(process.env.TOKEN);