Comment

class praw.models.Comment(reddit, id=None, url=None, _data=None)

A class that represents a reddit comments.

__init__(reddit, id=None, url=None, _data=None)

Construct an instance of the Comment object.

block()

Block the user who sent the item.

clear_vote()

Clear the authenticated user’s vote on the object.

Note

Votes must be cast by humans. That is, API clients proxying a human’s action one-for-one are OK, but bots deciding how to vote on content or amplifying a human’s vote are not. See the reddit rules for more details on what constitutes vote cheating. [Ref]

collapse()

Mark the item as collapsed.

Note

This method pertains only to objects which were retrieved via the inbox.

delete()

Delete the object.

disable_inbox_replies()

Disable inbox replies for the item.

downvote()

Downvote the object.

Note

Votes must be cast by humans. That is, API clients proxying a human’s action one-for-one are OK, but bots deciding how to vote on content or amplifying a human’s vote are not. See the reddit rules for more details on what constitutes vote cheating. [Ref]

edit(body)

Replace the body of the object with body.

Parameters:body – The markdown formatted content for the updated object.
Returns:The current instance after updating its attributes.
enable_inbox_replies()

Enable inbox replies for the item.

fullname

Return the object’s fullname.

A fullname is an object’s kind mapping like t3 followed by an underscore and the object’s base36 ID, e.g., t1_c5s96e0.

gild()

Gild the author of the item.

static id_from_url(url)

Get the ID of a comment from the full URL.

is_root

Return True when the comment is a top level comment.

mark_read()

Mark the item as read.

Note

This method pertains only to objects which were retrieved via the inbox.

mark_unread()

Mark the item as unread.

Note

This method pertains only to objects which were retrieved via the inbox.

mod

Provide an instance of CommentModeration.

parent()

Return the parent of the comment.

The returned parent will be an instance of either Comment, or Submission.

If this comment was obtained through a Submission, then its entire ancestry should be immediately available, requiring no extra network requests. However, if this comment was obtained through other means, e.g., reddit.comment('COMMENT_ID'), or reddit.inbox.comment_replies, then the returned parent may be a lazy instance of either Comment, or Submission.

Lazy Comment Example:

comment = reddit.comment('cklhv0f')
parent = comment.parent()
# `replies` is empty until the comment is refreshed
print(parent.replies)  # Output: []
parent.refresh()
print(parent.replies)  # Output is at least: [Comment(id='cklhv0f')]

Warning

Successive calls to parent() may result in a network request per call when the comment is not obtained through a Submission. See below for an example of how to minimize requests.

If you have a deeply nested comment and wish to most efficiently discover its top-most Comment ancestor you can chain successive calls to parent() with calls to refresh() at every 9 levels. For example:

comment = reddit.comment('dkk4qjd')
ancestor = comment
refresh_counter = 0
while not ancestor.is_root:
    ancestor = ancestor.parent()
    if refresh_counter % 9 == 0:
        ancestor.refresh()
    refresh_counter += 1
print('Top-most Ancestor: {}'.format(ancestor))

The above code should result in 5 network requests to Reddit. Without the calls to refresh() it would make at least 31 network requests.

parse(data, reddit)

Return an instance of cls from data.

Parameters:
  • data – The structured data.
  • reddit – An instance of Reddit.
refresh()

Refresh the comment’s attributes.

If using Reddit.comment() this method must be called in order to obtain the comment’s replies.

replies

Provide an instance of CommentForest.

reply(body)

Reply to the object.

Parameters:body – The markdown formatted content for a comment.
Returns:A Comment object for the newly created comment.
report(reason)

Report this object to the moderators of its subreddit.

Parameters:reason – The reason for reporting.
save(category=None)

Save the object.

Parameters:category – (Gold) The category to save to. If your user does not have gold this value is ignored by Reddit (default: None).
submission

Return the Submission object this comment belongs to.

uncollapse()

Mark the item as uncollapsed.

Note

This method pertains only to objects which were retrieved via the inbox.

unsave()

Unsave the object.

upvote()

Upvote the object.

Note

Votes must be cast by humans. That is, API clients proxying a human’s action one-for-one are OK, but bots deciding how to vote on content or amplifying a human’s vote are not. See the reddit rules for more details on what constitutes vote cheating. [Ref]

Note

This list of attributes is not complete. PRAW dynamically provides the attributes that Reddit returns via the API. Because those attributes are subject to change on Reddit’s end, PRAW makes no effort to document them, other than to instruct you on how to discover what is available. See Determine Available Attributes of an Object for detailed information.