2022-07-22 18:09:13 -04:00
|
|
|
const client = require("../index");
|
2022-09-28 18:00:36 -04:00
|
|
|
require("dotenv").config();
|
|
|
|
const { glob } = require("glob");
|
|
|
|
const { promisify } = require("util");
|
|
|
|
const globPromise = promisify(glob);
|
2022-07-22 18:09:13 -04:00
|
|
|
|
|
|
|
client.on("interactionCreate", async (interaction) => {
|
2022-09-28 18:00:36 -04:00
|
|
|
|
|
|
|
// Slash Commands
|
|
|
|
const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`);
|
|
|
|
const arrayOfSlashCommands = [];
|
|
|
|
|
|
|
|
// Map the slash commands into data to be processed
|
|
|
|
slashCommands.map((value) => {
|
|
|
|
const file = require(value);
|
|
|
|
const splitted = value.split("/");
|
|
|
|
const directory = splitted[splitted.length - 2];
|
|
|
|
|
|
|
|
if (!file?.name) return;
|
|
|
|
|
|
|
|
const properties = {
|
|
|
|
directory,
|
|
|
|
...file
|
|
|
|
};
|
|
|
|
client.slashCommands.set(file.name, properties);
|
|
|
|
|
|
|
|
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
|
|
|
|
|
|
|
|
// Push the data
|
|
|
|
arrayOfSlashCommands.push(file);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2022-07-22 18:09:13 -04:00
|
|
|
// Slash Command Handling
|
|
|
|
if (interaction.isChatInputCommand()) {
|
|
|
|
|
2022-09-28 18:00:36 -04:00
|
|
|
// Grabbing Command Data for this interaction
|
|
|
|
let commandData = []
|
|
|
|
|
|
|
|
// We use ForEach here to filter our array into the single commands info.
|
|
|
|
await arrayOfSlashCommands.forEach(command => {
|
|
|
|
if (command.name == interaction.commandName) {
|
|
|
|
commandData.push(command)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Process and Parse Data
|
|
|
|
let dataToProcess = JSON.stringify(commandData[0])
|
|
|
|
let parsedData = JSON.parse(dataToProcess)
|
|
|
|
|
2023-04-22 17:11:37 -04:00
|
|
|
|
|
|
|
if (interaction.commandName == "modal-example"){
|
|
|
|
console.log("Modal - Skipping defer")
|
|
|
|
} else {
|
2022-09-28 18:00:36 -04:00
|
|
|
// If the command is private, set ephemeral true else, set false
|
|
|
|
console.log(parsedData)
|
|
|
|
if (parsedData.private == true) {
|
|
|
|
await interaction.deferReply({
|
|
|
|
ephemeral: true
|
|
|
|
}).catch(() => {});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
await interaction.deferReply({
|
|
|
|
ephemeral: false
|
|
|
|
}).catch(() => {});
|
|
|
|
}
|
2023-04-22 17:11:37 -04:00
|
|
|
}
|
2022-09-28 18:00:36 -04:00
|
|
|
const cmd = client.slashCommands.get(interaction.commandName);
|
|
|
|
if (!cmd)
|
|
|
|
return interaction.followUp({
|
|
|
|
content: "An error has occurred "
|
|
|
|
});
|
2022-07-22 18:09:13 -04:00
|
|
|
|
2022-09-28 18:00:36 -04:00
|
|
|
const args = [];
|
2022-07-22 18:09:13 -04:00
|
|
|
|
2022-09-28 18:00:36 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
|
2022-07-22 18:09:13 -04:00
|
|
|
|
2022-09-28 18:00:36 -04:00
|
|
|
cmd.run(client, interaction, args);
|
2022-07-22 18:09:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Context Menu Handling
|
|
|
|
if (interaction.isContextMenuCommand()) {
|
2022-09-28 18:00:36 -04:00
|
|
|
await interaction.deferReply({
|
|
|
|
ephemeral: false
|
|
|
|
});
|
|
|
|
const command = client.slashCommands.get(interaction.commandName);
|
|
|
|
if (command) command.run(client, interaction);
|
2022-07-22 18:09:13 -04:00
|
|
|
}
|
2022-09-28 18:00:36 -04:00
|
|
|
});
|