Botanique/src/modals/loader.ts
Anri 23c6b6eb48 Meta: Use of Prettier (#58)
Usage of Prettier alongs with ESlint

Co-authored-by: Mylloon <kennel.anri@tutanota.com>
Reviewed-on: https://git.kennel.ml/ConfrerieDuKassoulait/Botanique/pulls/58
2023-01-17 23:11:22 +01:00

32 lines
1.1 KiB
TypeScript

import { readdir } from "fs/promises";
import { removeExtension } from "../utils/misc";
import { Client } from "discord.js";
export default async (client: Client) => {
// Dossier des modals
const modals_categories = (await readdir(__dirname)).filter(
(element) => !element.endsWith(".js") && !element.endsWith(".ts")
);
await Promise.all(
// For each categorie
modals_categories.map(async (modals_category) => {
// Retrieve all the commands
const modal_files = await readdir(`${__dirname}/${modals_category}`);
// Add the category to the collection for the help command
client.modals.categories.set(modals_category, modal_files.map(removeExtension));
// Add the modal
return Promise.all(
modal_files.map(async (modal_file) => {
const modal = (await import(`../modals/${modals_category}/${modal_file}`)).default;
// Add it to the collection so the interaction will work
client.modals.list.set(modal.data.name, modal);
return modal.data;
})
);
})
);
};