Class: User
models.User
A class representing a user.
Table of contents
Accessors
Methods
- getComments
- getModPermissionsForSubreddit
- getPosts
- getSnoovatarUrl
- getSocialLinks
- getUserFlairBySubreddit
- toJSON
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
permalink
• 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
| Name | Type | Description |
|---|---|---|
options | Omit<GetCommentsByUserOptions, "username"> | Options for the request |
Returns
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
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
options | Omit<GetPostsByUserOptions, "username"> | Options for the request |
Returns
A Listing of Post objects.
getSnoovatarUrl
▸ getSnoovatarUrl(): Promise<undefined | string>
Returns
Promise<undefined | string>
getSocialLinks
▸ 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();
getUserFlairBySubreddit
▸ getUserFlairBySubreddit(subreddit): Promise<undefined | UserFlair>
Retrieve the user's flair for the subreddit.
Parameters
| Name | Type | Description |
|---|---|---|
subreddit | string | The 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);
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[]> }