reddit.user¶
-
class
asyncpraw.models.
User
(reddit: asyncpraw.Reddit)¶ The user class provides methods for the currently authenticated user.
-
__init__
(reddit: asyncpraw.Reddit)¶ Initialize a User instance.
This class is intended to be interfaced with through
reddit.user
.
-
await
blocked
() → List[asyncpraw.models.Redditor]¶ Return a RedditorList of blocked Redditors.
-
contributor_subreddits
(**generator_kwargs: Union[str, int, Dict[str, str]]) → AsyncIterator[asyncpraw.models.Subreddit]¶ Return a
ListingGenerator
of contributor subreddits.These are subreddits that the user is a contributor of.
Additional keyword arguments are passed in the initialization of
ListingGenerator
.
-
await
friends
(user: Optional[Union[asyncpraw.models.Redditor, str]] = None) → Union[List[asyncpraw.models.Redditor], asyncpraw.models.Redditor]¶ Return a RedditorList of friends or a Redditor in the friends list.
- Parameters
user – Checks to see if you are friends with the Redditor. Either an instance of
Redditor
or a string can be given.- Returns
A list of Redditors, or a Redditor if you are friends with the given Redditor. The Redditor also has friend attributes.
- Raises
An instance of
asyncprawcore.exceptions.BadRequest
if you are not friends with the specified Redditor.
-
await
karma
() → Dict[asyncpraw.models.Subreddit, Dict[str, int]]¶ Return a dictionary mapping subreddits to their karma.
The returned dict contains subreddits as keys. Each subreddit key contains a sub-dict that have keys for
comment_karma
andlink_karma
. The dict is sorted in descending karma order.Note
Each key of the main dict is an instance of
Subreddit
. It is recommended to iterate over the dict in order to retrieve the values, preferably throughdict.items()
.
-
await
me
(use_cache: bool = True) → Optional[asyncpraw.models.Redditor]¶ Return a
Redditor
instance for the authenticated user.- Parameters
use_cache – When true, and if this function has been previously called, returned the cached version (default: True).
Note
If you change the Reddit instance’s authorization, you might want to refresh the cached value. Prefer using separate Reddit instances, however, for distinct authorizations.
Deprecated since version 7.2: In
read_only
mode this method returnsNone
. In Async PRAW 8 this method will raiseReadOnlyException
when called inread_only
mode. To operate in Async PRAW 8 mode, set the config variablepraw8_raise_exception_on_me
toTrue
.
-
await
multireddits
() → List[asyncpraw.models.Multireddit]¶ Return a list of multireddits belonging to the user.
-
classmethod
parse
(data: Dict[str, Any], reddit: asyncpraw.Reddit) → Any¶ Return an instance of
cls
fromdata
.- Parameters
data – The structured data.
reddit – An instance of
Reddit
.
-
preferences
() → asyncpraw.models.Preferences¶ Get an instance of
Preferences
.The preferences can be accessed as a
dict
like so:preferences = await reddit.user.preferences() print(preferences["show_link_flair"])
Preferences can be updated via:
await reddit.user.preferences.update(show_link_flair=True)
The
Preferences.update()
method returns the new state of the preferences as adict
, which can be used to check whether a change went through. Changes with invalid types or parameter names fail silently.original_preferences = await reddit.user.preferences() new_prefs = await original_preferences.update(invalid_param=123) print(original_preferences == new_prefs) # True, no change
-
subreddits
(**generator_kwargs: Union[str, int, Dict[str, str]]) → AsyncIterator[asyncpraw.models.Subreddit]¶ Return a
ListingGenerator
of subreddits the user is subscribed to.Additional keyword arguments are passed in the initialization of
ListingGenerator
.
-