2022-09-24 13:06:19 -04:00
|
|
|
const client = require("../index");
|
2022-09-28 17:58:24 -04:00
|
|
|
require("dotenv").config();
|
2023-01-08 03:01:54 -05:00
|
|
|
const { glob } = require("glob");
|
|
|
|
const { promisify } = require("util");
|
|
|
|
const globPromise = promisify(glob);
|
2022-09-24 13:06:19 -04:00
|
|
|
|
|
|
|
client.on("interactionCreate", async (interaction) => {
|
2023-01-08 03:01:54 -05:00
|
|
|
|
2022-09-28 17:58:24 -04:00
|
|
|
// Slash Commands
|
2023-01-08 03:01:54 -05:00
|
|
|
const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`);
|
|
|
|
const arrayOfSlashCommands = [];
|
|
|
|
slashCommands.map((value) => {
|
|
|
|
const file = require(value);
|
|
|
|
const splitted = value.split("/");
|
|
|
|
const directory = splitted[splitted.length - 2];
|
|
|
|
|
2022-09-28 17:58:24 -04:00
|
|
|
if (!file?.name) return;
|
2023-01-08 03:01:54 -05:00
|
|
|
|
|
|
|
const properties = { directory, ...file };
|
|
|
|
client.slashCommands.set(file.name, properties);
|
|
|
|
|
2022-09-28 17:58:24 -04:00
|
|
|
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
|
2023-01-08 03:01:54 -05:00
|
|
|
arrayOfSlashCommands.push(file);
|
2022-09-28 17:58:24 -04:00
|
|
|
});
|
|
|
|
|
2022-09-24 13:06:19 -04:00
|
|
|
// Slash Command Handling
|
|
|
|
if (interaction.isChatInputCommand()) {
|
2022-09-28 17:58:24 -04:00
|
|
|
|
2023-01-08 03:01:54 -05:00
|
|
|
let commandData = []
|
|
|
|
await arrayOfSlashCommands.forEach(command => {
|
|
|
|
console.log(command.name)
|
|
|
|
if (command.name == interaction.commandName) {
|
|
|
|
commandData.push(command)
|
2023-01-08 02:50:40 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-01-08 03:01:54 -05:00
|
|
|
let dataToProcess = JSON.stringify(commandData[0])
|
|
|
|
let parsedData = JSON.parse(dataToProcess)
|
|
|
|
|
|
|
|
if (parsedData.private == true) {
|
|
|
|
await interaction.deferReply({ ephemeral: true }).catch(() => { });
|
|
|
|
|
|
|
|
} else {
|
|
|
|
await interaction.deferReply({ ephemeral: false }).catch(() => { });
|
|
|
|
}
|
|
|
|
|
|
|
|
const cmd = client.slashCommands.get(interaction.commandName);
|
|
|
|
if (!cmd)
|
|
|
|
return interaction.followUp({ content: "An error has occurred " });
|
|
|
|
|
|
|
|
const args = [];
|
|
|
|
|
|
|
|
for (let option of interaction.options.data) {
|
|
|
|
if (option.type === "SUB_COMMAND") {
|
|
|
|
if (option.name) args.push(option.name);
|
|
|
|
option.options?.forEach((x) => {
|
|
|
|
if (x.value) args.push(x.value);
|
|
|
|
});
|
|
|
|
} else if (option.value) args.push(option.value);
|
|
|
|
}
|
2022-09-24 13:06:19 -04:00
|
|
|
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
|
|
|
|
|
|
|
|
cmd.run(client, interaction, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Context Menu Handling
|
|
|
|
if (interaction.isContextMenuCommand()) {
|
|
|
|
await interaction.deferReply({ ephemeral: false });
|
|
|
|
const command = client.slashCommands.get(interaction.commandName);
|
|
|
|
if (command) command.run(client, interaction);
|
|
|
|
}
|
2023-01-08 03:01:54 -05:00
|
|
|
|
2022-09-24 13:06:19 -04:00
|
|
|
});
|