Update commands to slash commands

This commit is contained in:
Logan Cusano
2023-02-25 03:25:07 -05:00
parent 49c80b7f5e
commit 02bf0ebda2
16 changed files with 370 additions and 223 deletions

View File

@@ -1,30 +1,43 @@
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;
module.exports = {
name: 'help',
description: 'Display this help message',
example: "help",
execute(message) {
messageText = "";
const commandsPath = path.resolve('./commands'); // Resolves from either working dir or __dirname
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
const commandsPath = path.resolve(__dirname, '../commands'); // Resolves from either working dir or __dirname
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
if (!command.isPrivileged){ // TODO - Need to add middleware for admins
if (messageText.length > 1 && messageText.slice(-2) != `\n`){
messageText += `\n`;
}
messageText += `**${prefix}${command.name}** - *${command.description}*`;
if (command.example) messageText += `\n\t\t***Usage:*** \`${command.example}\``
}
}
message.reply(messageText);
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());
}
}
};