This commit is contained in:
Tutur33
2024-03-02 21:15:14 +01:00
parent 90da5b1a97
commit 95daf7ef0f
10 changed files with 804 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import fs from 'fs';
import path from 'path';
module.exports = function loadCommands(client: any, dir: string) {
let count = 0;
fs.readdirSync(path.join(__dirname, dir)).forEach((file: string) => {
const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) {
count += loadCommands(client, path.join(dir, file));
} else if (file.endsWith('.js') || file.endsWith('.ts')) {
try {
delete require.cache[require.resolve(filePath)];
const command = require(filePath);
const fileName = file.replace(/\.js|\.ts/g, '');
command.name = fileName;
if (!command.category) {
const parentDir = path.basename(path.dirname(filePath));
command.category = parentDir === 'commands' ? 'other' : parentDir;
}
client.commands.set(fileName, command);
if (command.aliases) {
command.aliases.forEach((alias: string) => {
client.commands.set(alias, command);
});
}
count++;
} catch (error) {
console.error(`Failed to load file: ${filePath}`);
console.error(error);
}
}
});
return count;
}
+23
View File
@@ -0,0 +1,23 @@
import { Client } from 'discord.js';
import fs from 'fs';
import path from 'path';
module.exports = function loadEvents(client: Client, dir: string): number {
let count = 0;
fs.readdirSync(path.join(__dirname, dir)).forEach((file: string) => {
const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) {
loadEvents(client, path.join(dir, file));
} else if (file.endsWith('.js') || file.endsWith('.ts')) {
delete require.cache[require.resolve(filePath)];
const event = require(filePath);
if (typeof event.execute === 'function') {
client.on(event.name, (...args: any[]) => event.execute(...args, client)); // Specify the type of 'args' as an array of any type
count++;
} else {
console.error(`Event ${event.name} does not have an execute method.`);
}
}
});
return count;
}
+17
View File
@@ -0,0 +1,17 @@
const { Collection } = require('discord.js')
const { Client } = require('discord.js-selfbot-v13');
const loadEvents = require("./loadEvents");
const loadCommands = require("./loadCommands");
module.exports = function run(token: string) {
const client = new Client({ checkUpdate: false });
client.events = new Collection();
client.commands = new Collection();
console.log(`${loadEvents(client, '..\\events')} events loaded`);
console.log(`${loadCommands(client, '..\\commands')} commands loaded`);
client.login(token);
};