function commandsToArray(commands) { const commandsArray = []; commands.forEach(command => { if(command.options.length !== 0) { if(command.options[0].type === undefined) { // subcommands or subcommand group var data = JSON.parse(JSON.stringify(command.options[0])); if(data.type === 1) { // subcmd command.options.forEach(subcommand => { commandsArray.push({ name: `/${command.name} ${subcommand.name}`, description: subcommand.description }); }); } else if(data.type === 2) { // subcmd group data = JSON.parse(JSON.stringify(command.options)); data.forEach(group => { group.options.forEach(subcommand => { commandsArray.push({ name: `/${command.name} ${group.name} ${subcommand.name}`, description: subcommand.description }); }); }); } } else { // has options but isnt a subcmd or subcmd group commandsArray.push({ name: `/${command.name}`, description: command.description }); } } else { commandsArray.push({ name: `/${command.name}`, description: command.description }); } }) return commandsArray; }