SubredditMessage¶
- class asyncpraw.models.SubredditMessage(reddit, _data)¶
A class for messages to a subreddit.
Typical Attributes
Note
This table describes attributes that typically belong to objects of this class. Async PRAW dynamically provides the attributes that Reddit returns via the API. Since those attributes are subject to change on Reddit’s end, Async PRAW makes no effort to document any new/removed/changed attributes, other than to instruct you on how to discover what is available. As a result, this table of attributes may not be complete. See Determine Available Attributes of an Object for detailed information.
If you would like to add an attribute to this table, feel free to open a pull request.
Attribute
Description
authorProvides an instance of
Redditor.bodyThe body of the message, as Markdown.
body_htmlThe body of the message, as HTML.
created_utcTime the message was created, represented in Unix Time.
destProvides an instance of
Redditor. The recipient of the message.idThe ID of the message.
nameThe full ID of the message, prefixed with
t4_.subjectThe subject of the message.
subredditIf the message was sent from a subreddit, provides an instance of
Subreddit.was_commentWhether or not the message was a comment reply.
- Parameters:
reddit (asyncpraw.Reddit)
- await block()¶
Block the user who sent the item.
Note
This method pertains only to objects which were retrieved via the inbox.
Example usage:
comment = await reddit.comment("dkk4qjd") await comment.block() # or, identically: comment = await reddit.comment("dkk4qjd") await comment.author.block()
- Return type:
- await collapse()¶
Mark the item as collapsed.
Note
This method pertains only to objects which were retrieved via the inbox.
Example usage:
inbox = reddit.inbox() # select first inbox item and collapse it async for message in inbox: await message.collapse() break
See also
- Return type:
- property created_datetime: datetime¶
Return the creation time as a timezone-aware
datetime.datetime.The returned object is localized to the system’s timezone.
- await delete()¶
Delete the message.
Note
Reddit does not return an indication of whether or not the message was successfully deleted.
For example, to delete the most recent message in your inbox:
async for message in reddit.inbox.all(): await message.delete() break
- Return type:
- property fullname: str¶
Return the object’s fullname.
A fullname is an object’s kind mapping like
t3followed by an underscore and the object’s base36 ID, e.g.,t1_c5s96e0.
- await load()¶
Re-fetches the object.
This is used to explicitly fetch or re-fetch the object from reddit. This method can be used on any
RedditBaseobject.await reddit_base_object.load()
- Return type:
- await mark_read()¶
Mark a single inbox item as read.
Note
This method pertains only to objects which were retrieved via the inbox.
Example usage:
inbox = reddit.inbox.unread() async for message in inbox: # process unread messages ...
See also
To mark the whole inbox as read with a single network request, use
Inbox.mark_all_read()- Return type:
- await mark_unread()¶
Mark the item as unread.
Note
This method pertains only to objects which were retrieved via the inbox.
Example usage:
inbox = reddit.inbox(limit=10) async for message in inbox: # process messages ...
See also
- Return type:
- property parent: Message | None¶
Return the parent of the message if it exists.
Note
If the message is from an inbox listing, the returned parent will be lazy and must be fetched manually. For example:
async for message in reddit.inbox.all(limit=1): parent = message.parent await parent.load() print(parent.body)
- classmethod parse(data, reddit)¶
Return an instance of
MessageorSubredditMessagefromdata.
- await reply(body)¶
Reply to the object.
- Parameters:
body (
str) – The Markdown formatted content for a comment.- Return type:
- Returns:
A
CommentorMessageobject for the newly created comment or message orNoneif Reddit doesn’t provide one.- Raises:
asyncprawcore.exceptions.Forbiddenwhen attempting to reply to some items, such as locked submissions/comments or non-replyable messages.
A
Nonevalue can be returned if the target is a comment or submission in a quarantined subreddit and the authenticated user has not opt-ed into viewing the content. When this happens the comment will be successfully created on Reddit and can be retried by drawing the comment from the user’s comment history.Example usage:
submission = await reddit.submission("5or86n", fetch=False) await submission.reply("reply") comment = await reddit.comment("dxolpyc", fetch=False) await comment.reply("reply")
- await uncollapse()¶
Mark the item as uncollapsed.
Note
This method pertains only to objects which were retrieved via the inbox.
Example usage:
inbox = reddit.inbox() # select first inbox item and uncollapse it async for message in inbox: await message.uncollapse() break
See also
- Return type: