Both documents and folders both use the fm:discussion child association.
Folders already have a child association called 'cm:contains' for the sub folders and files. So for a folder you'll need to pick out the fm:discussion child association specifically.
It just so happens that documents usually don't have any child associations so referencing doc.children[0] would normally give you the fm:discussion child association (if its present). However, this is not guaranteed, documents could have other child associations too so your code should really be specific about the child association you mean in both scenarios.
Hopefully Kev can respond with the freemarker syntax you'll need to do that!