Skip to main content
Version: 0.10

Class: User

models.User

A class representing a user.

Table of contents

Accessors

Methods

Accessors

commentKarma

get commentKarma(): number

The amount of comment karma the user has.

Returns

number


createdAt

get createdAt(): Date

The date the user was created.

Returns

Date


id

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

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

Returns

`t2_${string}`

Example

't2_1w72';

isAdmin

get isAdmin(): boolean

Whether the user is admin.

Returns

boolean


linkKarma

get linkKarma(): number

The amount of link karma the user has.

Returns

number


modPermissions

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

The permissions the user has on the subreddit.

Returns

Map<string, ModeratorPermission[]>


nsfw

get nsfw(): boolean

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

Returns

boolean


get permalink(): string

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

Returns

string


url

get url(): string

Returns the HTTP URL for the user

Returns

string


username

get username(): string

The username of the user omitting the u/.

Returns

string

Example

'spez';

Methods

getComments

getComments(options): Listing<Comment>

Get the user's comments.

Parameters

NameTypeDescription
optionsOmit<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

NameTypeDescription
subredditNamestringname 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

NameTypeDescription
optionsOmit<GetPostsByUserOptions, "username">Options for the request

Returns

Listing<Post>

A Listing of Post objects.


getSnoovatarUrl

getSnoovatarUrl(): Promise<undefined | string>

Returns

Promise<undefined | string>


getUserFlairBySubreddit

getUserFlairBySubreddit(subreddit): Promise<undefined | UserFlair>

Retrieve the user's flair for the subreddit.

Parameters

NameTypeDescription
subredditstringThe name of the subreddit associated with the user's flair.

Returns

Promise<undefined | UserFlair>

Example

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

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();

toJSON

toJSON(): Pick<User, "username" | "id" | "nsfw" | "createdAt" | "linkKarma" | "commentKarma"> & { modPermissionsBySubreddit: Record<string, ModeratorPermission[]> }

Returns

Pick<User, "username" | "id" | "nsfw" | "createdAt" | "linkKarma" | "commentKarma"> & { modPermissionsBySubreddit: Record<string, ModeratorPermission[]> }

  • Table of contents
  • Accessors
    • commentKarma
    • createdAt
    • id
    • isAdmin
    • linkKarma
    • modPermissions
    • nsfw
    • permalink
    • url
    • username
  • Methods
    • getComments
    • getModPermissionsForSubreddit
    • getPosts
    • getSnoovatarUrl
    • getUserFlairBySubreddit
    • getSocialLinks
    • toJSON