myteams-api
Version:
An MyTeams Module to use discord.js and Twitch API easily
34 lines • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegisterSlash = void 0;
const glob_1 = require("glob");
const util_1 = require("util");
const Error_1 = require("../Utils/Error");
const globPromise = util_1.promisify(glob_1.glob);
async function RegisterSlash(client, folderName, Collection, guild) {
if (!folderName)
throw new Error_1.MyTeamsError("A folder name its required.");
if (!client)
throw new Error_1.MyTeamsError("Please provide a Client");
if (!Collection)
throw new Error_1.MyTeamsError("Please provide a Discord.Collection");
const slashCommands = await globPromise(`${process.cwd()}/${folderName}/*/*.js`);
const arrayOfSlashCommands = [];
slashCommands.map((value) => {
const file = require(value);
if (!file?.name)
return;
Collection.set(file.name, file);
arrayOfSlashCommands.push(file);
});
client.on('ready', async () => {
if (guild) {
await client.guilds.cache.get(guild).commands.set(arrayOfSlashCommands);
}
else {
client.application.commands.set(arrayOfSlashCommands);
}
});
}
exports.RegisterSlash = RegisterSlash;
//# sourceMappingURL=SlashHandler.js.map