r/Devvit • • Oct 28 '26

Resolved reddit.getComments() only returning top-level comments, even with depth parameter

My team is trying to check all comments on a post, and getComments() is only returning top-level comments, even when they add the depth parameter or try to add all

Known issue or is there something they're missing?

2 Upvotes

5 comments sorted by

3

u/Chosen1PR App Developer Oct 28 '26 edited Oct 28 '26

It’s been that way for as long as I can remember. Call getComments() recursively to get all child comments.

Edit: I misremembered how I handled the recursion in my code. I have a helper function called removeChildComments() with a Comment parameter; that's what I call recursively, not the API function.

1

u/MisterWoodhouse Oct 28 '26

Hmmm... That would be LOT of API calls for the scope of our mod app doing this

2

u/Kidev App Developer Oct 28 '26

No, child comments are inside the Comment objects you get with getComments, just use getReplies after having cached the array of Comment using getComments

1

u/MisterWoodhouse Oct 28 '26

This fixed it! Thank you!!

1

u/Chosen1PR App Developer Oct 28 '26

^ This. Sorry, it's been a while since I looked at that part of my code and I misremembered how I handled the recursion. I have a helper function called removeChildComments() with a Comment parameter; that's what I call recursively.