Files
Emmelia-Link-Flayer-Rewrite/commands/help.js
2023-02-25 03:25:07 -05:00

43 lines
1.3 KiB
JavaScript

const fs = require('fs');
const path = require('node:path');
const { SlashCommandBuilder } = require('discord.js');
const { DebugBuilder } = require("../utilities/debugBuilder");
const log = new DebugBuilder("server", "help");
const prefix = process.env.PREFIX;
const commandsPath = path.resolve(__dirname, '../commands'); // Resolves from either working dir or __dirname
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Display this help message'),
example: "help",
isPrivileged: false,
async execute(interaction) {
try{
messageText = "";
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if (!command.isPrivileged){ // TODO - Need to add middleware for admins
if (messageText.length > 1 && messageText.slice(-2) != `\n`){
messageText += `\n`;
}
messageText += `**/${command.data.name}** - *${command.data.description}*`;
if (command.example) messageText += `\n\t\t***Usage:*** \`${command.example}\``
}
}
await interaction.reply(messageText);
}catch(err){
log.ERROR(err)
//await interaction.reply(err.toString());
}
}
};