SubredditMessage#

class praw.models.SubredditMessage(reddit: praw.Reddit, _data: Dict[str, Any])#

A class for messages to a subreddit.

Typical Attributes

Note

This table describes attributes that typically belong to objects of this class. PRAW dynamically provides the attributes that Reddit returns via the API. Since those attributes are subject to change on Reddit’s end, 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

author

Provides an instance of Redditor.

body

The body of the message, as Markdown.

body_html

The body of the message, as HTML.

created_utc

Time the message was created, represented in Unix Time.

dest

Provides an instance of Redditor. The recipient of the message.

id

The ID of the message.

name

The full ID of the message, prefixed with t4_.

subject

The subject of the message.

subreddit

If the message was sent from a subreddit, provides an instance of Subreddit.

was_comment

Whether or not the message was a comment reply.

__init__(reddit: praw.Reddit, _data: Dict[str, Any])#

Initialize a Message instance.

block()#

Block the user who sent the item.

Note

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

Example usage:

comment = reddit.comment("dkk4qjd")
comment.block()

# or, identically:

comment.author.block()
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 message = next(inbox)
message.collapse()

See also

uncollapse()

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:

next(reddit.inbox.all()).delete()
property fullname: str#

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.

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()

for message in inbox:
    # process unread messages
    ...

See also

mark_unread()

To mark the whole inbox as read with a single network request, use Inbox.mark_all_read()

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)

for message in inbox:
    # process messages
    ...

See also

mark_read()

mute()#

Mute the sender of this SubredditMessage.

For example, to mute the sender of the first SubredditMessage in the authenticated users’ inbox:

from praw.models import SubredditMessage

msg = next(
    message for message in reddit.inbox.all() if isinstance(message, SubredditMessage)
)
msg.mute()
property parent: praw.models.Message | None#

Return the parent of the message if it exists.

classmethod parse(data: Dict[str, Any], reddit: praw.Reddit)#

Return an instance of Message or SubredditMessage from data.

Parameters:
  • data – The structured data.

  • reddit – An instance of Reddit.

reply(body: str) praw.models.Comment | praw.models.Message | None#

Reply to the object.

Parameters:

body – The Markdown formatted content for a comment.

Returns:

A Comment or Message object for the newly created comment or message or None if Reddit doesn’t provide one.

Raises:

prawcore.exceptions.Forbidden when attempting to reply to some items, such as locked submissions/comments or non-replyable messages.

A None value 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 = reddit.submission("5or86n")
submission.reply("reply")

comment = reddit.comment("dxolpyc")
comment.reply("reply")
unblock_subreddit()#

Unblock a subreddit.

Note

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

For example, to unblock all blocked subreddits that you can find by going through your inbox:

from praw.models import SubredditMessage

subs = set()
for item in reddit.inbox.messages(limit=None):
    if isinstance(item, SubredditMessage):
        if (
            item.subject == "[message from blocked subreddit]"
            and str(item.subreddit) not in subs
        ):
            item.unblock_subreddit()
            subs.add(str(item.subreddit))
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
message = next(inbox)
message.uncollapse()

See also

collapse()

unmute()#

Unmute the sender of this SubredditMessage.

For example, to unmute the sender of the first SubredditMessage in the authenticated users’ inbox:

from praw.models import SubredditMessage

msg = next(
    message for message in reddit.inbox.all() if isinstance(message, SubredditMessage)
)
msg.unmute()