add game command

This commit is contained in:
Tutur33
2024-02-26 11:20:08 +01:00
parent a9d92fbff6
commit 7ee772a6b9
23 changed files with 229 additions and 160 deletions
+2 -5
View File
@@ -1,25 +1,22 @@
import fs from 'fs';
import path from 'path';
module.exports = function loadEvents(client: any, dir: string) {
module.exports = function loadCommands(client: any, dir: string) {
let count = 0;
dir = `../${dir}`
fs.readdirSync(path.join(__dirname, dir)).forEach((file: string) => {
const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) {
count += loadCommands(path.join(dir, file));
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;
console.log(command);
if (!command.category) {
const parentDir = path.basename(path.dirname(filePath));
command.category = parentDir === 'commands' ? 'other' : parentDir;
}
console.log(command);
client.commands.set(fileName, command);
if (command.aliases) {
command.aliases.forEach((alias: string) => {
-1
View File
@@ -4,7 +4,6 @@ import path from 'path';
module.exports = function loadEvents(client: Client, dir: string): number {
let count = 0;
dir = `../${dir}`
fs.readdirSync(path.join(__dirname, dir)).forEach((file: string) => {
const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) {
+2 -2
View File
@@ -8,8 +8,8 @@ module.exports = function run(token: string) {
client.events = new Collection();
client.commands = new Collection();
console.log(`${loadEvents(client, 'events')} events loaded`);
console.log(`${loadCommands(client, 'commands')} commands loaded`);
console.log(`${loadEvents(client, '..\\events')} events loaded`);
console.log(`${loadCommands(client, '..\\commands')} commands loaded`);
client.login(token);
};