Skip to main content

User

@devvit/reddit v0.15.5-dev


Class: User

A class representing a user.

Extended by​

Accessors​

about​

Get Signature​

get about(): string

The user's public description about themselves. May be empty.

Returns​

string


commentKarma​

Get Signature​

get commentKarma(): number

The amount of comment karma the user has.

Returns​

number


createdAt​

Get Signature​

get createdAt(): Date

The date the user was created.

Returns​

Date


displayName​

Get Signature​

get displayName(): string

The display name of the user. May be different from their username.

Returns​

string


hasRedditPremium​

Get Signature​

get hasRedditPremium(): boolean

Whether the user has Reddit Premium.

Returns​

boolean


hasVerifiedEmail​

Get Signature​

get hasVerifiedEmail(): boolean

Indicates whether or not the user has verified their email address.

Returns​

boolean


id​

Get Signature​

get id(): `t2_${string}`

The ID (starting with t2_) of the user to retrieve.

Example​
't2_1w72'
Returns​

`t2_${string}`


isAdmin​

Get Signature​

get isAdmin(): boolean

Whether the user is a Reddit employee.

Returns​

boolean


isModerator​

Get Signature​

get isModerator(): boolean

Whether the user is a moderator of any subreddit.

Returns​

boolean


linkKarma​

Get Signature​

get linkKarma(): number

The amount of link karma the user has.

Returns​

number


modPermissions​

Get Signature​

get modPermissions(): Map<string, ModeratorPermission[]>

The permissions the user has on the subreddit.

Returns​

Map<string, ModeratorPermission[]>


nsfw​

Get Signature​

get nsfw(): boolean

Whether the user's profile is marked as NSFW (Not Safe For Work).

Returns​

boolean


Get Signature​

get permalink(): string

Returns a permalink path relative to https://www.reddit.com

Returns​

string


showNsfw​

Get Signature​

get showNsfw(): boolean

Whether the user is over 18 and wishes to see NSFW content.

Returns​

boolean


url​

Get Signature​

get url(): string

Returns the HTTP URL for the user

Returns​

string


username​

Get Signature​

get username(): string

The username of the user omitting the u/.

Example​
'spez'
Returns​

string

Methods​

getComments()​

getComments(options): Listing<Comment>

Get the user's comments.

Parameters​

options​

Omit<GetCommentsByUserOptions, "username">

Options for the request

Returns​

Listing<Comment>

A Listing of Comment objects.


getModPermissionsForSubreddit()​

getModPermissionsForSubreddit(subredditName): Promise<ModeratorPermission[]>

Get the mod permissions the user has on the subreddit if they are a moderator.

Parameters​

subredditName​

string

name of the subreddit

Returns​

Promise<ModeratorPermission[]>

the moderator permissions the user has on the subreddit


getPosts()​

getPosts(options): Listing<Post>

Get the user's posts.

Parameters​

options​

Omit<GetPostsByUserOptions, "username">

Options for the request

Returns​

Listing<Post>

A Listing of Post objects.


getSnoovatarUrl()​

getSnoovatarUrl(): Promise<string | undefined>

Gets this user's public Snoovatar image URL.

Returns​

Promise<string | undefined>

The image URL, or undefined if this user has no Snoovatar image.

Throws​

If the account is unavailable or the lookup fails.


getSocialLinks(): Promise<UserSocialLink[]>

Gets social links of the user

Returns​

Promise<UserSocialLink[]>

A Promise that resolves an Array of UserSocialLink objects

Example​

const socialLinks = await user.getSocialLinks();

getTrophies()​

getTrophies(): Promise<Trophy[]>

Get the trophies displayed on this user's profile.

Returns​

Promise<Trophy[]>

A Promise that resolves to an array of Trophy objects.


getUserFlairBySubreddit()​

getUserFlairBySubreddit(subreddit): Promise<UserFlair | undefined>

Retrieve the user's flair for the subreddit.

Parameters​

subreddit​

string

The name of the subreddit associated with the user's flair.

Returns​

Promise<UserFlair | undefined>

Example​

const username = "badapple"
const subredditName = "mysubreddit"
const user = await reddit.getUserByUsername(username);
const userFlair = await user.getUserFlairBySubreddit(subredditName);

getUserKarmaFromCurrentSubreddit()​

getUserKarmaFromCurrentSubreddit(): Promise<GetUserKarmaForSubredditResponse>

Returns the karma for this User in the current subreddit. The user making the request must be a moderator of the subreddit to read another user's karma in the subreddit. An exception is if the specified user is the same as the user making the request.

Returns​

Promise<GetUserKarmaForSubredditResponse>

The GetUserKarmaForSubredditResponse, containing the user's karma for comments and posts in the subreddit.


toJSON()​

toJSON(): Pick<User, "id" | "nsfw" | "username" | "createdAt" | "linkKarma" | "commentKarma"> & object

Returns​

Pick<User, "id" | "nsfw" | "username" | "createdAt" | "linkKarma" | "commentKarma"> & object