mirror of
https://github.com/JonnyBro/JaBa.git
synced 2025-01-04 09:43:03 +05:00
35 lines
932 B
JavaScript
35 lines
932 B
JavaScript
import { client } from "../../index.js";
|
|
import { getFilePaths } from "../../utils/get-path.js";
|
|
import { toFileURL } from "../../utils/resolve-file.js";
|
|
import registerCommands from "./functions/registerCommands.js";
|
|
|
|
export const commands = [];
|
|
|
|
export const init = async () => {
|
|
await buildCommands();
|
|
|
|
await registerCommands({
|
|
client,
|
|
commands,
|
|
});
|
|
};
|
|
|
|
const buildCommands = async () => {
|
|
const commandFilePaths = (await getFilePaths("./newCommands", true)).filter(path => path.endsWith(".js"));
|
|
|
|
for (const cmdFilePath of commandFilePaths) {
|
|
const { data, run } = await import(toFileURL(cmdFilePath));
|
|
|
|
if (!data || !data.name) {
|
|
console.warn(`Command ${cmdFilePath} does not have a data object or name`);
|
|
continue;
|
|
}
|
|
|
|
if (typeof run !== "function") {
|
|
console.warn(`Command ${cmdFilePath} does not have a run function or it is not a function`);
|
|
continue;
|
|
}
|
|
|
|
commands.push({ data, run });
|
|
}
|
|
};
|