Modmail¶
- class asyncpraw.models.reddit.subreddit.Modmail(subreddit)¶
Provides modmail functions for a
Subreddit.For example, to send a new modmail from r/test to u/spez with the subject
"test"along with a message body of"hello":subreddit = await reddit.subreddit("test") await subreddit.modmail.create(subject="test", body="hello", recipient="spez")
- Parameters:
subreddit (asyncpraw.models.Subreddit)
- await __call__(id=None, *, mark_read=False, fetch=True)¶
Return an individual conversation.
- Parameters:
- Return type:
For example:
subreddit = await reddit.subreddit("test") await subreddit.modmail("2gmz", mark_read=True)
If you don’t need the object fetched right away (e.g., to utilize a class method) you can do:
subreddit = await reddit.subreddit("test") message = await subreddit.modmail("2gmz", fetch=False) await message.archive()
To print all messages from a conversation as Markdown source:
subreddit = await reddit.subreddit("test") conversation = await subreddit.modmail("2gmz", mark_read=True) for message in conversation.messages: print(message.body_markdown)
ModmailConversation.useris a special instance ofRedditorwith extra attributes describing the non-moderator user’s recent posts, comments, and modmail messages within the subreddit, as well as information on active bans and mutes. This attribute does not exist on internal moderator discussions.For example, to print the user’s ban status:
subreddit = await reddit.subreddit("test") conversation = await subreddit.modmail("2gmz", mark_read=True) print(conversation.user.ban_status)
To print a list of recent submissions by the user:
subreddit = await reddit.subreddit("test") conversation = await subreddit.modmail("2gmz", mark_read=True) print(conversation.user.recent_posts)
- __init__(subreddit)¶
Initialize a
Modmailinstance.- Parameters:
subreddit (Subreddit)
- Return type:
None
- await bulk_read(*, other_subreddits=None, state=None)¶
Mark conversations for subreddit(s) as read.
Note
Due to server-side restrictions, r/all is not a valid subreddit for this method. Instead, use
subreddits()to get a list of subreddits using the new modmail.- Parameters:
other_subreddits (
list[Subreddit|str] |None) – A list ofSubredditinstances for which to mark conversations (default:None).state (
str|None) – Can be one of:"all","archived", or"highlighted","inprogress","join_requests","mod","new","notifications", or"appeals"(default:"all")."all"does not include internal, archived, or appeals conversations.
- Return type:
- Returns:
A list of lazy
ModmailConversationinstances that were marked read.
For example, to mark all notifications for a subreddit as read:
subreddit = await reddit.subreddit("test") await subreddit.modmail.bulk_read(state="notifications")
- conversations(*, other_subreddits=None, sort=None, state=None, **generator_kwargs)¶
Generate
ModmailConversationobjects for subreddit(s).- Parameters:
other_subreddits (
list[Subreddit|str] |None) – A list ofSubredditinstances for which to fetch conversations (default:None).sort (
str|None) – Can be one of:"mod","recent","unread", or"user"(default:"recent").state (
str|None) – Can be one of:"all","archived","highlighted","inprogress","join_requests","mod","new","notifications", or"appeals"(default:"all")."all"does not include internal, archived, or appeals conversations.generator_kwargs (Any)
- Return type:
Additional keyword arguments are passed in the initialization of
ListingGenerator.For example:
sub = await reddit.subreddit("all") async for conversation in sub.modmail.conversations(state="mod"): # do stuff with conversations ...
- await create(*, author_hidden=False, body, recipient, subject)¶
Create a new
ModmailConversation.- Parameters:
- Return type:
- Returns:
A
ModmailConversationobject for the newly created conversation.
subreddit = await reddit.subreddit("test") redditor = await reddit.redditor("bboe") await subreddit.modmail.create(subject="Subject", body="Body", recipient=redditor)
- await subreddits()¶
Yield subreddits using the new modmail that the user moderates.
For example:
sub = await reddit.subreddit("all") async for subreddit in sub.modmail.subreddits(): # do stuff with subreddit ...
- Return type:
- await unread_count()¶
Return unread conversation count by conversation state.
At time of writing, possible states are:
"archived","highlighted","inprogress","join_requests","mod","new","notifications", or"appeals".For example, to print the count of unread moderator discussions:
subreddit = await reddit.subreddit("test") unread_counts = await subreddit.modmail.unread_count() print(unread_counts["mod"])