Update commands to slash commands
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user