reddit.user
- class praw.models.User(reddit: praw.Reddit)
The
User
class provides methods for the currently authenticated user.- __init__(reddit: praw.Reddit)
Initialize an
User
instance.This class is intended to be interfaced with through
reddit.user
.
- blocked() List[praw.models.Redditor]
Return a
RedditorList
of blockedRedditor
s.
- contributor_subreddits(**generator_kwargs: Union[str, int, Dict[str, str]]) Iterator[praw.models.Subreddit]
Return a
ListingGenerator
of contributorSubreddit
s.These are subreddits in which the user is an approved user.
Additional keyword arguments are passed in the initialization of
ListingGenerator
.To print a list of the subreddits that you are an approved user in, try:
for subreddit in reddit.user.contributor_subreddits(limit=None): print(str(subreddit))
- friends(*, user: Optional[Union[praw.models.Redditor, str]] = None) Union[List[praw.models.Redditor], praw.models.Redditor]
Return a
RedditorList
of friends or aRedditor
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
Redditor
s, or a singleRedditor
ifuser
is specified. TheRedditor
instance(s) returned also has friend attributes.- Raises
An instance of
RedditAPIException
if you are not friends with the specifiedRedditor
.
- karma() Dict[praw.models.Subreddit, Dict[str, int]]
Return a dictionary mapping
Subreddit
s 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()
.
- me(*, use_cache: bool = True) Optional[praw.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 separateReddit
instances, however, for distinct authorizations.Deprecated since version 7.2: In
read_only
mode this method returnsNone
. In PRAW 8 this method will raiseReadOnlyException
when called inread_only
mode. To operate in PRAW 8 mode, set the config variablepraw8_raise_exception_on_me
toTrue
.
- moderator_subreddits(**generator_kwargs: Union[str, int, Dict[str, str]]) Iterator[praw.models.Subreddit]
Return a
ListingGenerator
subreddits that the user moderates.Additional keyword arguments are passed in the initialization of
ListingGenerator
.To print a list of the names of the subreddits you moderate, try:
for subreddit in reddit.user.moderator_subreddits(limit=None): print(str(subreddit))
See also
- multireddits() List[praw.models.Multireddit]
Return a list of
Multireddit
s belonging to the user.
- classmethod parse(data: Dict[str, Any], reddit: praw.Reddit) Any
Return an instance of
cls
fromdata
.- Parameters
data – The structured data.
reddit – An instance of
Reddit
.
- pin(submission: praw.models.Submission, *, num: int = None, state: bool = True)
Set the pin state of a submission on the authenticated user’s profile.
- Parameters
submission – An instance of
Submission
that will be pinned/unpinned.num –
If specified, the slot in which the submission will be pinned into. If there is a submission already in the specified slot, it will be replaced. If
None
or there is not a submission in the specified slot, the first available slot will be used (default:None
). If all slots are used the following will occur:Old Reddit:
The submission in the last slot will be unpinned.
The remaining pinned submissions will be shifted down a slot.
The new submission will be pinned in the first slot.
New Reddit:
The submission in the first slot will be unpinned.
The remaining pinned submissions will be shifted up a slot.
The new submission will be pinned in the last slot.
Note
At the time of writing (10/22/2021), there are 4 pin slots available and pins are in reverse order on old Reddit. If
num
is an invalid value, Reddit will ignore it and the same behavior will occur as ifnum
isNone
.state –
True
pins the submission,False
unpins (default:True
).
- Raises
prawcore.BadRequest
when pinning a removed or deleted submission.- Raises
prawcore.Forbidden
when pinning a submission the authenticated user is not the author of.
submission = next(reddit.user.me().submissions.new()) reddit.user.pin(submission)
- preferences() praw.models.Preferences
Get an instance of
Preferences
.The preferences can be accessed as a
dict
like so:preferences = reddit.user.preferences() print(preferences["show_link_flair"])
Preferences can be updated via:
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 = reddit.user.preferences() new_preferences = reddit.user.preferences.update(invalid_param=123) print(original_preferences == new_preferences) # True, no change
- subreddits(**generator_kwargs: Union[str, int, Dict[str, str]]) Iterator[praw.models.Subreddit]
Return a
ListingGenerator
ofSubreddit
s the user is subscribed to.Additional keyword arguments are passed in the initialization of
ListingGenerator
.To print a list of the subreddits that you are subscribed to, try:
for subreddit in reddit.user.subreddits(limit=None): print(str(subreddit))
- trusted() List[praw.models.Redditor]
Return a
RedditorList
of trustedRedditor
s.To display the usernames of your trusted users and the times at which you decided to trust them, try:
trusted_users = reddit.user.trusted() for user in trusted_users: print(f"User: {user.name}, time: {user.date}")