Redditor¶
- class asyncpraw.models.Redditor(reddit, name=None, fullname=None, _data=None)¶
A class representing the users of Reddit.
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.
Note
Shadowbanned accounts are treated the same as non-existent accounts, meaning that they will not have any attributes.
Note
Suspended/banned accounts will only return the
nameandis_suspendedattributes.Attribute
Description
comment_karmaThe comment karma for the
Redditor.commentsProvide an instance of
SubListingfor comment access.submissionsProvide an instance of
SubListingfor submission access.created_utcTime the account was created, represented in Unix Time.
has_verified_emailWhether or not the
Redditorhas verified their email.icon_imgThe url of the Redditors’ avatar.
idThe ID of the
Redditor.is_employeeWhether or not the
Redditoris a Reddit employee.is_friendWhether or not the
Redditoris friends with the authenticated user.is_modWhether or not the
Redditormods any subreddits.is_goldWhether or not the
Redditorhas active Reddit Premium status.is_suspendedWhether or not the
Redditoris currently suspended.link_karmaThe link karma for the
Redditor.nameThe Redditor’s username.
subredditIf the
Redditorhas created a user-subreddit, provides aUserSubredditwith additional attributes.- Parameters:
reddit (asyncpraw.Reddit)
name (str | None)
fullname (str | None)
- __init__(reddit, name=None, fullname=None, _data=None)¶
Initialize a
Redditorinstance.- Parameters:
- Return type:
None
Exactly one of
name,fullnameor_datamust be provided.
- await block()¶
Block the
Redditor.For example, to block
Redditoru/spez:redditor = await reddit.redditor("spez") await redditor.block()
Note
Blocking a trusted user will remove that user from your trusted list.
See also
- Return type:
- comments()¶
Provide an instance of
SubListingfor comment access.For example, to output the first line of all new comments by u/spez try:
redditor = await reddit.redditor("spez") async for comment in redditor.comments.new(limit=None): print(comment.body.split("\\n", 1)[0][:79])
- Return type:
- controversial(*, time_filter='all', **generator_kwargs)¶
Return a
ListingGeneratorfor controversial items.- Parameters:
time_filter (
str) – Can be one of:"all","day","hour","month","week", or"year"(default:"all").generator_kwargs (Unpack[ListingGeneratorKwargs])
- Raises:
ValueErroriftime_filteris invalid.- Return type:
Additional keyword arguments are passed in the initialization of
ListingGenerator.This method can be used like:
reddit.domain("imgur.com").controversial(time_filter="week") multireddit = await reddit.multireddit(redditor="samuraisam", name="programming") multireddit.controversial(time_filter="day") redditor = await reddit.redditor("spez") redditor.controversial(time_filter="month") redditor = await reddit.redditor("spez") redditor.comments.controversial(time_filter="year") redditor = await reddit.redditor("spez") redditor.submissions.controversial(time_filter="all") subreddit = await reddit.subreddit("all") subreddit.controversial(time_filter="hour")
- 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 distrust()¶
Remove the
Redditorfrom your whitelist of trusted users.For example, to remove
Redditoru/spez from your whitelist:redditor = await reddit.redditor("spez") await redditor.distrust()
See also
- Return type:
- downvoted(**generator_kwargs)¶
Return a
ListingGeneratorfor items the user has downvoted.- Return type:
- Returns:
A
ListingGeneratorobject which yieldsCommentorSubmissionobjects the user has downvoted.- Raises:
asyncprawcore.Forbiddenif the user is not authorized to access the list.Note
Since this function returns a
ListingGeneratorthe exception may not occur until sometime after this function has returned.- Parameters:
generator_kwargs (Unpack[ListingGeneratorKwargs])
Additional keyword arguments are passed in the initialization of
ListingGenerator.For example, to get all downvoted items of the authenticated user:
current_user = await reddit.user.me() async for item in current_user.downvoted(): print(item.id)
- await friend(*, note=None)¶
Friend the
Redditor.- Parameters:
note (
str|None) – A note to save along with the relationship. Requires Reddit Premium (default:None).- Return type:
Calling this method subsequent times will update the note.
For example, to friend u/spez:
redditor = await reddit.redditor("spez") await redditor.friend()
To add a note to the friendship (requires Reddit Premium):
redditor = await reddit.redditor("spez") await redditor.friend(note="My favorite admin")
- await friend_info()¶
Return a
Redditorinstance with specific friend-related attributes.- Return type:
- Returns:
A
Redditorinstance with fieldsdate,id, and possiblynoteif the authenticated user has Reddit Premium.
For example, to get the friendship information of
Redditoru/spez:redditor = await reddit.redditor("spez") info = await redditor.friend_info friend_data = info.date
- 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.
Return a
ListingGeneratorfor items the user has hidden.- Return type:
- Returns:
A
ListingGeneratorobject which yieldsCommentorSubmissionobjects the user has hid.- Raises:
asyncprawcore.Forbiddenif the user is not authorized to access the list.Note
Since this function returns a
ListingGeneratorthe exception may not occur until sometime after this function has returned.- Parameters:
generator_kwargs (Unpack[ListingGeneratorKwargs])
Additional keyword arguments are passed in the initialization of
ListingGenerator.For example, to get all hidden items of the authenticated user:
current_user = await reddit.user.me() async for item in current_user.hidden(): print(item.id)
- hot(**generator_kwargs)¶
Return a
ListingGeneratorfor hot items.Additional keyword arguments are passed in the initialization of
ListingGenerator.This method can be used like:
reddit.domain("imgur.com").hot() multireddit = await reddit.multireddit(redditor="samuraisam", name="programming") multireddit.hot() redditor = await reddit.redditor("spez") redditor.hot() redditor = await reddit.redditor("spez") redditor.comments.hot() redditor = await reddit.redditor("spez") redditor.submissions.hot() subreddit = await reddit.subreddit("all") subreddit.hot()
- Return type:
- Parameters:
generator_kwargs (Unpack[ListingGeneratorKwargs])
- 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 message(*, from_subreddit=None, message, subject)¶
Send a message to a
Redditoror aSubreddit’s moderators (modmail).- Parameters:
from_subreddit (
Subreddit|str|None) –A
Subredditinstance or string to send the message from. When provided, messages are sent from the subreddit rather than from the authenticated user.Note
The authenticated user must be a moderator of the subreddit and have the
mailmoderator permission.message (
str) – The message content.subject (
str) – The subject of the message.
- Return type:
For example, to send a private message to u/spez, try:
redditor = await reddit.redditor("spez", fetch=False) await redditor.message(subject="TEST", message="test message from Async PRAW")
To send a message to u/spez from the moderators of r/test try:
redditor = await reddit.redditor("spez", fetch=False) await redditor.message( subject="TEST", message="test message from r/test", from_subreddit="test" )
To send a message to the moderators of r/test, try:
subreddit = await reddit.subreddit("test") await subreddit.message(subject="TEST", message="test PM from Async PRAW")
- await moderated()¶
Return a list of the redditor’s moderated subreddits.
- Return type:
- Returns:
A list of
Subredditobjects. Return[]if the redditor has no moderated subreddits.- Raises:
asyncprawcore.ServerErrorin certain circumstances. See the note below.
Note
The redditor’s own user profile subreddit will not be returned, but other user profile subreddits they moderate will be returned.
Usage:
redditor = await reddit.redditor("spez") async for subreddit in redditor.moderated(): print(subreddit.display_name) print(subreddit.title)
Note
A
asyncprawcore.ServerErrorexception may be raised if the redditor moderates a large number of subreddits. If that happens, try switching to read-only mode. For example,reddit.read_only = True redditor = await reddit.redditor("reddit") async for subreddit in redditor.moderated(): print(str(subreddit))
It is possible that requests made in read-only mode will also raise a
asyncprawcore.ServerErrorexception.When used in read-only mode, this method does not retrieve information about subreddits that require certain special permissions to access, e.g., private subreddits and premium-only subreddits.
See also
- await multireddits()¶
Return a list of the redditor’s public multireddits.
For example, to to get
Redditoru/spez’s multireddits:redditor = await reddit.redditor("spez") multireddits = await redditor.multireddits()
- Return type:
- new(**generator_kwargs)¶
Return a
ListingGeneratorfor new items.Additional keyword arguments are passed in the initialization of
ListingGenerator.This method can be used like:
reddit.domain("imgur.com").new() multireddit = await reddit.multireddit(redditor="samuraisam", name="programming") multireddit.new() redditor = await reddit.redditor("spez") redditor.new() redditor = await reddit.redditor("spez") redditor.comments.new() redditor = await reddit.redditor("spez") redditor.submissions.new() subreddit = await reddit.subreddit("all") subreddit.new()
- Return type:
- Parameters:
generator_kwargs (Unpack[ListingGeneratorKwargs])
- notes()¶
Provide an instance of
RedditorModNotes.This provides an interface for managing moderator notes for a redditor.
Note
The authenticated user must be a moderator of the provided subreddit(s).
For example, all the notes for u/spez in r/test can be iterated through like so:
redditor = await reddit.redditor("spez") async for note in redditor.notes.subreddits("test"): print(f"{note.label}: {note.note}")
- Return type:
- overview()¶
Provide an instance of
SubListingfor overview access.The overview combines a Redditor’s comments and submissions, mirroring the user overview page on Reddit.
For example, to output the first line of all top items by u/spez try:
redditor = await reddit.redditor("spez") async for item in redditor.overview.top(time_filter="all"): print(str(item)[:79])
- Return type:
- classmethod parse(data, reddit)¶
Return an instance of
clsfromdata.
- saved(**generator_kwargs)¶
Return a
ListingGeneratorfor items the user has saved.- Return type:
- Returns:
A
ListingGeneratorobject which yieldsCommentorSubmissionobjects the user has saved.- Raises:
asyncprawcore.Forbiddenif the user is not authorized to access the list.Note
Since this function returns a
ListingGeneratorthe exception may not occur until sometime after this function has returned.- Parameters:
generator_kwargs (Unpack[ListingGeneratorKwargs])
Additional keyword arguments are passed in the initialization of
ListingGenerator.For example, to get all saved items of the authenticated user:
current_user = await reddit.user.me() async for item in current_user.saved(limit=None): print(item.id)
- stream()¶
Provide an instance of
RedditorStream.Streams can be used to indefinitely retrieve new comments made by a redditor, like:
redditor = await reddit.redditor("spez") async for comment in redditor.stream.comments(): print(comment)
Additionally, new submissions can be retrieved via the stream. In the following example all submissions are fetched via the redditor u/spez:
redditor = await reddit.redditor("spez") async for submission in redditor.stream.submissions(): print(submission)
- Return type:
- submissions()¶
Provide an instance of
SubListingfor submission access.For example, to output the title’s of top 100 of all time submissions for u/spez try:
redditor = await reddit.redditor("spez") async for submission in redditor.submissions.top(time_filter="all"): print(submission.title)
- Return type:
- top(*, time_filter='all', **generator_kwargs)¶
Return a
ListingGeneratorfor top items.- Parameters:
time_filter (
str) – Can be one of:"all","day","hour","month","week", or"year "``(default: ``"all").generator_kwargs (Unpack[ListingGeneratorKwargs])
- Raises:
ValueErroriftime_filteris invalid.- Return type:
Additional keyword arguments are passed in the initialization of
ListingGenerator.This method can be used like:
reddit.domain("imgur.com").top(time_filter="week") multireddit = await reddit.multireddit(redditor="samuraisam", name="programming") multireddit.top(time_filter="day") redditor = await reddit.redditor("spez") redditor.top(time_filter="month") redditor = await reddit.redditor("spez") redditor.comments.top(time_filter="year") redditor = await reddit.redditor("spez") redditor.submissions.top(time_filter="all") subreddit = await reddit.subreddit("all") subreddit.top(time_filter="hour")
- await trophies()¶
Return a list of the redditor’s trophies.
- Return type:
- Returns:
A list of
Trophyobjects. Return[]if the redditor has no trophies.- Raises:
RedditAPIExceptionif the redditor doesn’t exist.
Usage:
redditor = await reddit.redditor("spez") async for trophy in redditor.trophies(): print(trophy.name) print(trophy.description)
- await trust()¶
Add the
Redditorto your whitelist of trusted users.Trusted users will always be able to send you PMs.
Example usage:
redditor = await reddit.redditor("AaronSw") await redditor.trust()
Use the
accept_pmsparameter ofPreferences.update()to toggle youraccept_pmssetting between"everyone"and"whitelisted". For example:# Accept private messages from everyone: await reddit.user.preferences.update(accept_pms="everyone") # Only accept private messages from trusted users: await reddit.user.preferences.update(accept_pms="whitelisted")
You may trust a user even if your
accept_pmssetting is switched to"everyone".Note
You are allowed to have a user on your blocked list and your friends list at the same time. However, you cannot trust a user who is on your blocked list.
See also
- Return type:
- await unblock()¶
Unblock the
Redditor.For example, to unblock
Redditoru/spez:redditor = await reddit.redditor("spez") await redditor.unblock()
- Return type:
- await unfriend()¶
Unfriend the
Redditor.For example, to unfriend
Redditoru/spez:redditor = await reddit.redditor("spez") await redditor.unfriend()
- Return type:
- upvoted(**generator_kwargs)¶
Return a
ListingGeneratorfor items the user has upvoted.- Return type:
- Returns:
A
ListingGeneratorobject which yieldsCommentorSubmissionobjects the user has upvoted.- Raises:
asyncprawcore.Forbiddenif the user is not authorized to access the list.Note
Since this function returns a
ListingGeneratorthe exception may not occur until sometime after this function has returned.- Parameters:
generator_kwargs (Unpack[ListingGeneratorKwargs])
Additional keyword arguments are passed in the initialization of
ListingGenerator.For example, to get all upvoted items of the authenticated user:
current_user = await reddit.user.me() async for item in current_user.upvoted(): print(item.id)