CappeDiem / Discord.js-bot-template

Basic bot template with event and command handler
MIT License
60 stars 27 forks source link

how to make command handler check sub-folders of folder "commands"? #2

Closed chilaxree closed 2 years ago

chilaxree commented 3 years ago

I wanna organize my commands into sub-folders but the command handler wont see my commands. is there a way to do it?

Akif9748 commented 3 years ago
fs.readdirSync('./commands').forEach(dir => {
  const commandFiles = fs.readdirSync(`./commands/${dir}/`).filter(file => file.endsWith('.js'));
  for (const file of commandFiles) {
    const jsfile = require(`./commands/${dir}/${file}`);
   bot.commands.set(jsfile.help.name, jsfile);

  }
})
CappeDiem commented 3 years ago
fs.readdirSync('./commands').forEach(dir => {
  const commandFiles = fs.readdirSync(`./commands/${dir}/`).filter(file => file.endsWith('.js'));
  for (const file of commandFiles) {
    const jsfile = require(`./commands/${dir}/${file}`);
   bot.commands.set(jsfile.help.name, jsfile);
  }
})

That code will load command files that are inside a sub-folders inside the commands folder but not command files that are inside the main commands folder. I might be implementing something that will load command files from the main folder and sub-folders at a later date

CappeDiem commented 2 years ago

implemented code in ab4688b56aaebed847499290ef459b22a774660e and it should do this and allow command files in the main commands directory aswell