Comment¶
Besides retrieving comments similarly to submissions using their ID or fetching them through a subreddit’s listings, comments can be obtained from the submission they were made in like so:
submission = await reddit.submission("h7mna9")
async for comment in submission.comments():
print(comment)
- class apraw.models.Comment(reddit: Reddit, data: Dict, submission: Submission = None, author: apraw.models.reddit.redditor.Redditor = None, subreddit: Subreddit = None, replies: Union[CommentForest, List] = None)¶
The model representing comments.
- mod: CommentModeration
The
CommentModerationinstance to aid in moderating the comment.- kind: str
The item’s kind / type.
- url: str
The URL pointing to this comment.
Typical Attributes
This table describes attributes that typically belong to objects of this class. Attributes are dynamically provided by the
aPRAWBaseclass and may vary depending on the status of the response and expected objects.Attribute
Description
all_awardingsA list of awardings added to the comment.
approved_at_utcThe UTC timestamp at which the comment was approved by the moderators.
approved_byThe moderator who approved this comment if applicable.
approvedWhether the comment has been approved by the moderators.
archivedWhether the comment has been archived.
author_flair_background_colorThe comment author’s flair background color if applicable.
author_flair_css_classThe comment author’s flair CSS class if applicable.
author_flair_richtextThe comment author’s flair text if applicable.
author_flair_template_idThe comment author’s flair template ID if applicable.
author_flair_text_colorThe comment author’s flair text color if applicable.
author_flair_textThe comment author’s flair text if applicable.
author_flair_typeThe comment author’s flair type if applicable.
author_fullnameThe comment author’s ID prepended with
t2_.author_patreon_flairThe comment author’s Patreon flair if applicable.
authorThe comment author’s username.
banned_at_utcNonebanned_byNonebody_htmlThe HTML version of the comment’s body.
bodyThe comment’s markdown body.
can_gildWhether the logged-in user can gild the comment.
can_mod_postboolcollapsed_reasonNonecollapsedWhether the comment should be collapsed by clients.
controversialityA score on the comment’s controversiality based on its up- and downvotes.
created_utcThe parsed UTC
datetimeon which the comment was made.createdA timestamp on which the comment was created.
distinguishedThe type of distinguishment the comment hsa received.
downsThe number of downvotes the comment has received.
editedWhether the comment has been edited from its original state.
gildedThe number of awards this comment has received.
gildingsA dictionary of gilds the comment has received.
idThe comment’s ID.
ignore_reportsWhether reports should be ignored on this comment.
is_submitterWhether the logged-in user is the submitter of this comment.
likesThe overall upvote score on this comment.
link_authorThe username of the comment submission’s author.
link_idThe ID of the submission this comment was made in.
link_permalink/link_urlA URL to the comment’s submission.
link_titleThe comment’s submission title.
lockedWhether the comment has been locked by the moderators.
mod_noteNotes added to the comment by moderators if applicable.
mod_reason_byThe moderator who added a removal reason if applicable.
mod_reason_titleThe mod reason’s title if applicable.
mod_reportsA list of reports made on this comment filed by moderators.
nameThe comment’s ID prepended with
t1_.no_followboolnum_commentsThe number of replies made in this submission.
num_reportsThe number of reports on this comment.
over_18Whether the comment has been marked NSFW.
parent_idThe comment’s parent ID, either
link_idor the ID of another comment.permalinkThe comment’s permalink.
quarantineboolremoval_reasonA removal reason set by moderators if applicable.
removedWhether the comment has been removed by the moderators of the subreddit.
repliesA list of replies made under this comment, usually empty at first.
report_reasonsReport reasons added to the comment.
savedWhether the logged-in user has saved this comment.
score_hiddenWhether clients should hide the comment’s score.
scoreThe overall upvote score on this comment.
send_repliesWhether the OP has enabled reply notifications.
spamWhether the comment has been flagged as spam.
stickiedWhether the comment has been stickied by the moderators.
subreddit_idThe comment subreddit’s ID prepended with
t5_.subreddit_name_prefixedThe comment’s subreddit name prefixed with “r/”.
subreddit_typeThe type of the subreddit the submission was posted on (public, restricted, private).
subredditThe name of the subreddit this comment was made in.
total_awards_receivedThe number of awards this comment has received.
upsThe number of upvotes this comment has received.
user_reportsA list of user reports filed for this comment.
Note
Many of these attributes are only available if the logged-in user has moderator access to the item.
- async author() apraw.models.reddit.redditor.Redditor¶
Retrieve the item’s author as a
Redditor.- Returns
author – The item’s author.
- Return type
- async clear_vote()¶
Clear user up- and downvotes on the item.
- Returns
resp – The API response JSON.
- Return type
Dict
- async delete()¶
Delete the item.
- Returns
resp – The API response JSON.
- Return type
Dict
- async downvote()¶
Downvote the item.
- Returns
resp – The API response JSON.
- Return type
Dict
- async fetch()¶
Fetch this item’s information from a suitable API endpoint.
- Returns
update – Whether ReactivePy attributes have been changed.
- Return type
bool
- property fullname¶
Get the ID prepended with its kind.
- Returns
fullname – The item’s ID prepended with its kind such as t1_.
- Return type
str
- async hide()¶
Hide the item.
- Returns
resp – The API response JSON.
- Return type
Dict
- async link() Submission¶
Retrieve the submission this item belongs to as a
Submission.- Returns
submission – The item’s parent submission.
- Return type
- async monitor(max_wait=16)¶
Continuously fetch this comment’s data to react to changes in the data.
This can be used in combination with the callbacks offered by ReactivePy to be notified on changes in specific fields on this comment. For more information on ReactivePy view the GitHub repo.
Callbacks can be assigned as follows:
async def on_change(*args): for arg in args: print(f"{arg.name} changed to {arg.value}.") comment.on_change(on_change)
Note
Callbacks will work regardless of them being asynchronous or synchronous, as aPRAW’s models use the
_async_bulk_update()method offered by ReactivePy’s interface.- Parameters
max_wait (int) – The maximum amount of time to wait between requests if no updates were previously recognized.
- async save(category: str = '')¶
Save the item in a category.
- Parameters
category (str, optional) – The category name.
- Returns
resp – The API response JSON.
- Return type
Dict
- async submission() Submission¶
Retrieve the submission this item belongs to as a
Submission.- Returns
submission – The item’s parent submission.
- Return type
- async subreddit() Subreddit¶
Retrieve the subreddit this item was made in as a
Subreddit.- Returns
subreddit – The subreddit this item was made in.
- Return type
- async unhide()¶
Unhide the item.
- Returns
resp – The API response JSON.
- Return type
Dict
- async unsave()¶
Unsave the item.
- Returns
resp – The API response JSON.
- Return type
Dict
- async upvote()¶
Upvote the item.
- Returns
resp – The API response JSON.
- Return type
Dict