hullcss-discord-bot/handler/index.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-05-10 01:17:25 +01:00
const { glob } = require("glob");
const { promisify } = require("util");
const { Client } = require("discord.js");
2022-05-11 21:37:08 +01:00
2022-05-10 01:17:25 +01:00
const globPromise = promisify(glob);
/**
* @param {Client} client
*/
module.exports = async (client) => {
// Commands
const commandFiles = await globPromise(`${process.cwd()}/commands/**/*.js`);
commandFiles.map((value) => {
const file = require(value);
const splitted = value.split("/");
const directory = splitted[splitted.length - 2];
if (file.name) {
const properties = { directory, ...file };
client.commands.set(file.name, properties);
}
});
// Events
const eventFiles = await globPromise(`${process.cwd()}/events/*.js`);
eventFiles.map((value) => require(value));
2022-05-11 21:37:08 +01:00
// Slash Commands
2022-06-02 02:14:39 +01:00
const slashCommands = await globPromise(
`${process.cwd()}/SlashCommands/*/*.js`
);
2022-05-11 21:16:49 +01:00
const arrayOfSlashCommands = [];
slashCommands.map((value) => {
const file = require(value);
if (!file?.name) return;
client.slashCommands.set(file.name, file);
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
arrayOfSlashCommands.push(file);
});
client.on("ready", async () => {
2022-06-27 09:51:53 +01:00
await client.application.commands.set(arrayOfSlashCommands);
2022-05-11 21:16:49 +01:00
});
2022-06-02 02:14:39 +01:00
};