Initial Code
This commit is contained in:
31
src/handlers/interaction_handler.ts
Normal file
31
src/handlers/interaction_handler.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user