32 lines
959 B
TypeScript
32 lines
959 B
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
|
|
import ms from "ms";
|
|
import BotClient from "../libs/BotClient";
|
|
|
|
const wait = (delay: number) => new Promise((resolve) => setTimeout(resolve, delay));
|
|
|
|
|
|
function isAction(file: string) {
|
|
return file.endsWith(".ts") || file.endsWith(".js");
|
|
}
|
|
|
|
function ScanDir(Discord: any, client: BotClient, dir: any) {
|
|
fs.readdirSync(dir).forEach((file) => {
|
|
if(isAction(file)) return loadAction(Discord, client, `${dir}/${file}`);
|
|
else return ScanDir(Discord, client, `${dir}/${file}`);
|
|
});
|
|
}
|
|
|
|
async function loadAction(Discord: any, client: BotClient, file: any) {
|
|
const action = new (await import(file)).default();
|
|
client.action.set(action.getId(), action);
|
|
}
|
|
|
|
export default async(Discord: any, client: BotClient) => {
|
|
ScanDir(Discord, client, path.join(__dirname, `../interactions/`));
|
|
await wait(ms("5s"));
|
|
client.logger.log(`${client.action.size} - Actions Loaded`);
|
|
}
|
|
|