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
CommentModeration
instance 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
aPRAWBase
class and may vary depending on the status of the response and expected objects.Attribute
Description
all_awardings
A list of awardings added to the comment.
approved_at_utc
The UTC timestamp at which the comment was approved by the moderators.
approved_by
The moderator who approved this comment if applicable.
approved
Whether the comment has been approved by the moderators.
archived
Whether the comment has been archived.
author_flair_background_color
The comment author’s flair background color if applicable.
author_flair_css_class
The comment author’s flair CSS class if applicable.
author_flair_richtext
The comment author’s flair text if applicable.
author_flair_template_id
The comment author’s flair template ID if applicable.
author_flair_text_color
The comment author’s flair text color if applicable.
author_flair_text
The comment author’s flair text if applicable.
author_flair_type
The comment author’s flair type if applicable.
author_fullname
The comment author’s ID prepended with
t2_
.author_patreon_flair
The comment author’s Patreon flair if applicable.
author
The comment author’s username.
banned_at_utc
None
banned_by
None
body_html
The HTML version of the comment’s body.
body
The comment’s markdown body.
can_gild
Whether the logged-in user can gild the comment.
can_mod_post
bool
collapsed_reason
None
collapsed
Whether the comment should be collapsed by clients.
controversiality
A score on the comment’s controversiality based on its up- and downvotes.
created_utc
The parsed UTC
datetime
on which the comment was made.created
A timestamp on which the comment was created.
distinguished
The type of distinguishment the comment hsa received.
downs
The number of downvotes the comment has received.
edited
Whether the comment has been edited from its original state.
gilded
The number of awards this comment has received.
gildings
A dictionary of gilds the comment has received.
id
The comment’s ID.
ignore_reports
Whether reports should be ignored on this comment.
is_submitter
Whether the logged-in user is the submitter of this comment.
likes
The overall upvote score on this comment.
link_author
The username of the comment submission’s author.
link_id
The ID of the submission this comment was made in.
link_permalink
/link_url
A URL to the comment’s submission.
link_title
The comment’s submission title.
locked
Whether the comment has been locked by the moderators.
mod_note
Notes added to the comment by moderators if applicable.
mod_reason_by
The moderator who added a removal reason if applicable.
mod_reason_title
The mod reason’s title if applicable.
mod_reports
A list of reports made on this comment filed by moderators.
name
The comment’s ID prepended with
t1_
.no_follow
bool
num_comments
The number of replies made in this submission.
num_reports
The number of reports on this comment.
over_18
Whether the comment has been marked NSFW.
parent_id
The comment’s parent ID, either
link_id
or the ID of another comment.permalink
The comment’s permalink.
quarantine
bool
removal_reason
A removal reason set by moderators if applicable.
removed
Whether the comment has been removed by the moderators of the subreddit.
replies
A list of replies made under this comment, usually empty at first.
report_reasons
Report reasons added to the comment.
saved
Whether the logged-in user has saved this comment.
score_hidden
Whether clients should hide the comment’s score.
score
The overall upvote score on this comment.
send_replies
Whether the OP has enabled reply notifications.
spam
Whether the comment has been flagged as spam.
stickied
Whether the comment has been stickied by the moderators.
subreddit_id
The comment subreddit’s ID prepended with
t5_
.subreddit_name_prefixed
The comment’s subreddit name prefixed with “r/”.
subreddit_type
The type of the subreddit the submission was posted on (public, restricted, private).
subreddit
The name of the subreddit this comment was made in.
total_awards_received
The number of awards this comment has received.
ups
The number of upvotes this comment has received.
user_reports
A 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