This usually helps to add a stack so that people can see the actual error. However, as a PRAW developer, I know that the error is something like MoreComments type has no attribute body .
There are three easy ways to solve your problem. First, just wrap the if "Cricketbot" in try / except and ignore the attribute error.
try: if "Cricketbot..." ... except AttributeError: pass
This is not terribly interesting. The second way is to make sure that you are actually working with an object with the body attribute, which can be done in two ways:
First, you need to explicitly check if the attribute exists:
for comment in flat_comments: if not hasattr(comment, 'body'): continue ...
Secondly, make sure that you are actually working with Comment objects, not with the MoreComments object:
for comment in flat_comments: if not isinstance(comment, praw.objects.Comment): continue ...
However, when you run any of the above solutions, you actually do not process all the comments for the view, since you are missing everything that is hidden behind the MoreComments [ ref ] object. To replace the MoreComments object MoreComments some (replacing all of them can be very inefficient) comments require the use of the replace_more_comments function before aligning the tree:
submission = r.get_submission(submission_id=subid[i]) submission.replace_more_comments(limit=16, threshold=10) flat_comments = praw.helpers.flatten_tree(submission.comments)
Setting limit=16 and threshold=10 means making no more than 16 additional requests and only making requests that will lead to at least 10 additional comments. You can play with these values ββas you wish, but note that for each replacement an additional request is required (2 seconds), and some of them give only one comment.
I hope this helps.