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