I am trying to create Nested commands in discord.js to make my bot read subfolders in my command folder (discord.js) Everything is basically in the title
command_handler.js:
const fs = require('fs')
module.exports = (client, Discord) => {
const command_files = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'))
for (const file of command_files) {
const command = require(`../commands/${file}`);
if (command.name) {
client.commands.set(command.name, command);
} else {
continue;
}
}
}
Most of Index.js:
const Discord = require('discord.js');
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
const token = process.env['DISCORD_TOKEN']
const fs = require('fs');
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler => {
require(`./handlers/${handler}`)(client, Discord);
})
// Command Handler
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`)
client.commands.set(command.name, command)
}
// client.login token
client.login(token)
Thanks in advance