-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
104 lines (87 loc) · 4.53 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const { Client, GatewayIntentBits, REST, Routes, Collection } = require("discord.js");
const path = require("path");
const fs = require("fs");
const { TOKEN, MONGODB_URI } = require("./config.json");
const chalk = require("chalk");
const mongoose = require("mongoose")
class NekoTicket {
constructor() {
mongoose.connect(MONGODB_URI).then(() => {
console.log(chalk.default.green(`[${chalk.default.white('NekoTicket')}] -> [${chalk.default.white('INFO')}] -> Connected to Mongodb`));
}).catch((err) => {
console.log(chalk.default.red(`[${chalk.default.white('NekoTicket')}] -> [${chalk.default.white('ERROR')}] -> MongoDB connection error:`, err));
})
this.client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
this.client.commands = new Collection()
this.loadCommands();
this.loadEvents();
this.setupEventHandlers();
}
loadCommands() {
const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js') || fs.lstatSync(path.join(commandsPath, file)).isDirectory());
this.commandsToDeploy = [];
console.log(chalk.default.green(`[${chalk.default.white('NekoTicket')}] -> [${chalk.default.white('INFO')}] -> ${chalk.default.green('Loading Commands...')}`));
for (const folderOrFile of commandFiles) {
const fullPath = path.join(commandsPath, folderOrFile);
if (fs.lstatSync(fullPath).isDirectory()) {
const folderPath = fullPath;
const commandFilesInFolder = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'));
for (const file of commandFilesInFolder) {
const command = require(path.join(folderPath, file));
this.client.commands.set(command.data.name, command);
this.commandsToDeploy.push(command.data.toJSON());
console.log(chalk.default.green(`[${chalk.default.white('NekoTicket')}] -> [${chalk.default.white('INFO')}] -> ${chalk.default.green(`Loaded Slash Commands ${command.data.name} from /${folderOrFile}/${file}`)}`));
}
} else {
const command = require(fullPath);
this.client.commands.set(command.data.name, command);
this.commandsToDeploy.push(command.data.toJSON());
console.log(chalk.default.green(`[${chalk.default.white('NekoTicket')}] -> [${chalk.default.white('INFO')}] -> ${chalk.default.green(`Loaded Commands ${command.data.name} from /${folderOrFile}`)}`));
}
}
}
loadEvents() {
const eventsPath = path.join(__dirname, "events")
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(path.join(eventsPath, file));
if (event.once) {
this.client.once(event.name, (...args) => event.execute(...args, this.client));
} else {
this.client.on(event.name, (...args) => event.execute(...args, this.client));
}
console.log(chalk.default.green(`[${chalk.default.white('NekoTicket')}] -> [${chalk.default.white('INFO')}] -> ${chalk.default.green(`Loaded Events ${event.name}`)}`));
}
console.log(chalk.default.green(`[${chalk.default.white('NekoTicket')}] -> [${chalk.default.white('INFO')}] -> Loading All Events Successfully !`));
}
async deployCommands() {
const rest = new REST({ version: '10' }).setToken(TOKEN);
try {
await rest.put(
Routes.applicationCommands(this.client.user.id),
{ body: this.commandsToDeploy },
);
console.log(chalk.default.green(`[${chalk.default.white('NekoTicket')}] -> [${chalk.default.white('INFO')}] -> Loading All Commands Successfully !`));
} catch (error) {
console.error(error);
}
}
setupEventHandlers() {
this.client.once('ready', async () => {
console.log(chalk.default.green(`[${chalk.default.white('NekoTicket')}] -> [${chalk.default.white('INFO')}] -> Logged in as ${this.client.user.tag}!`));
await this.deployCommands();
});
}
login() {
this.client.login(TOKEN);
}
}
const bot = new NekoTicket();
bot.login();