joel joel joel
This commit is contained in:
35
commands/index.ts
Normal file
35
commands/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { readdirSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { Command } from "./command";
|
||||
|
||||
export const readCommands = async (): Promise<Command[]> => {
|
||||
const foldersPath = path.join(__dirname);
|
||||
const commandFolders = readdirSync(foldersPath, {
|
||||
withFileTypes: true,
|
||||
})
|
||||
.filter((file) => file.isDirectory())
|
||||
.map((file) => file.name);
|
||||
|
||||
let commands: Command[] = [];
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
const commandFiles = readdirSync(commandsPath).filter((file) =>
|
||||
file.endsWith(".ts")
|
||||
);
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath).default as Command;
|
||||
// Set a new item in the Collection with the key as the command name and the value as the exported module
|
||||
if ("data" in command && "execute" in command) {
|
||||
commands.push({ data: command.data, execute: command.execute });
|
||||
} else {
|
||||
console.log(
|
||||
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
};
|
||||
Reference in New Issue
Block a user