Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

547
Visualizações
How can I fix my help commands (discord.js)

Currently I am using node.js So I can't require a command and I am unable to find a folder code :

    module.exports = {
    name: 'cmds',
    description: 'Shows the commands.',
    aliases: 'commands,help',
    cooldown: 1000,
    execute(client, msg, args) {
        const prettyms = require('pretty-ms')
        const author = msg.author
        const authorMember = msg.member
        const user = msg.mentions.users.first()
        const userMember = msg.mentions.members.first()
        const authorOrUser = user || author
        const authorOrUserMember = userMember || authorMember
        const fs = require('fs')
        const { MessageEmbed } = require("discord.js")
        const embed = new MessageEmbed()
        function getCommand(cmd) {
            return client.commands.get(`${cmd}`)
        }
        for (const category of fs.readdirSync(`../commands`)) {
            for (const cmd of fs.readdirSync(`../${category}`)) {
                const command = require(`../${category}/${cmd}`)
                console.log(command.name)
            }
        }
        embed.setAuthor(`Commands : ${client.commands.size}`)
        embed.setDescription("`<> means required, () means optional and | means it is an alias of a command`")
        embed.setFooter(`Made by 3F1VE#2276`)
        embed.setTimestamp(Date.now())
        embed.setTitle(`Commands`)
        embed.setColor('RANDOM')
        msg.reply({ embeds: [embed] })
    }
}

The problem is I cannot find a way to get the commands folder properly. Here are the files files

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You would need to set the folder list wherever you fetch yhem on startup or fetch them everything in the command(not recommended)

const { readdirSync } = require("fs");
module.exports = (bot) => {
  readdirSync("./commands/").map((dir) => {
    const commands = readdirSync(`./commands/${dir}/`).map((cmd) => {
      let pull = require(`../commands/${dir}/${cmd}`);
      bot.commands.set(pull.name, pull);
      if (pull.aliases) {
        pull.aliases.map((p) => bot.aliases.set(p, pull));
      }
    });
  });
  console.log(`All commands loaded\(Quantity\:${bot.commands.size} \)`)
};

You can change the above provided code with minor changes to fetch the folders in the command itself

Please remember this is pseudo code and would need changes to fit your use case please don't expect it to work out of thr box

about 4 years ago · Juan Pablo Isaza Relatório

0

Apparently I typed in the path wrong.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda