60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
|
|
module.exports = (client) => {
|
|
const modalsPath = path.join(
|
|
__dirname,
|
|
"../modals"
|
|
);
|
|
|
|
if (!fs.existsSync(modalsPath)) {
|
|
console.log(
|
|
`[WARNING] Modal directory not found: ${modalsPath}`
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
const modalFiles = fs
|
|
.readdirSync(modalsPath)
|
|
.filter(file =>
|
|
file.endsWith(".js")
|
|
);
|
|
|
|
let count = 0;
|
|
|
|
for (const file of modalFiles) {
|
|
const filePath = path.join(
|
|
modalsPath,
|
|
file
|
|
);
|
|
|
|
const modal = require(filePath);
|
|
|
|
if (
|
|
!modal.customId ||
|
|
typeof modal.execute !== "function"
|
|
) {
|
|
console.log(
|
|
`[WARNING] Modal ${file} is missing "customId" or "execute".`
|
|
);
|
|
|
|
continue;
|
|
}
|
|
|
|
client.modals.set(
|
|
modal.customId,
|
|
modal
|
|
);
|
|
|
|
console.log(
|
|
`[MODAL] Registered "${modal.customId}" from ${file}`
|
|
);
|
|
|
|
count++;
|
|
}
|
|
|
|
console.log(
|
|
`[${count}] Modal(s) initialized`
|
|
);
|
|
}; |