Skip to main content
Version: Next

Class: Subreddit

models.Subreddit

A class representing a subreddit.

Table of contents

Accessors

Methods

Accessors

createdAt

get createdAt(): Date

The creation date of the subreddit.

Returns

Date


description

get description(): undefined | string

The description of the subreddit.

Returns

undefined | string


id

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

The ID (starting with t5_) of the subreddit to retrieve. e.g. t5_2qjpg

Returns

`t5_${string}`


language

get language(): string

The language of the subreddit.

Returns

string


name

get name(): string

The name of a subreddit omitting the r/.

Returns

string


nsfw

get nsfw(): boolean

Whether the subreddit is marked as NSFW (Not Safe For Work).

Returns

boolean


numberOfActiveUsers

get numberOfActiveUsers(): number

The number of active users of the subreddit.

Returns

number


numberOfSubscribers

get numberOfSubscribers(): number

The number of subscribers of the subreddit.

Returns

number


get permalink(): string

Returns a permalink path (R2 bug: subreddit.url is a permalink, and does not have a subreddit.permalink field)

Returns

string


postFlairsEnabled

get postFlairsEnabled(): boolean

Whether the post flairs are enabled for this subreddit.

Returns

boolean


settings

get settings(): SubredditSettings

The settings of the subreddit.

Returns

SubredditSettings


title

get title(): undefined | string

The title of the subreddit.

Returns

undefined | string


type

get type(): SubredditType

The type of subreddit (public, private, etc.).

Returns

SubredditType


url

get url(): string

Returns the HTTP URL for the subreddit. (R2 bug: subreddit.url is a permalink path and does not return a fully qualified URL in subreddit.url)

Returns

string


userFlairsEnabled

get userFlairsEnabled(): boolean

Whether the user flairs are enabled for this subreddit.

Returns

boolean


usersCanAssignPostFlairs

get usersCanAssignPostFlairs(): boolean

Whether the user can assign post flairs. This is only true if the post flairs are enabled.

Returns

boolean


usersCanAssignUserFlairs

get usersCanAssignUserFlairs(): boolean

Whether the user can assign user flairs. This is only true if the user flairs are enabled.

Returns

boolean

Methods

addWikiContributor

addWikiContributor(username): Promise<void>

Parameters

NameType
usernamestring

Returns

Promise<void>


approveUser

approveUser(username): Promise<void>

Parameters

NameType
usernamestring

Returns

Promise<void>


banUser

banUser(options): Promise<void>

Parameters

NameType
optionsOmit<BanUserOptions, "subredditName">

Returns

Promise<void>


banWikiContributor

banWikiContributor(options): Promise<void>

Parameters

NameType
optionsOmit<BanWikiContributorOptions, "subredditName">

Returns

Promise<void>


createPostFlairTemplate

createPostFlairTemplate(options): Promise<FlairTemplate>

Parameters

NameType
optionsOmit<CreateFlairTemplateOptions, "subredditName">

Returns

Promise<FlairTemplate>


createUserFlairTemplate

createUserFlairTemplate(options): Promise<FlairTemplate>

Parameters

NameType
optionsOmit<CreateFlairTemplateOptions, "subredditName">

Returns

Promise<FlairTemplate>


getApprovedUsers

getApprovedUsers(options?): Listing<User>

Parameters

NameType
optionsGetUsersOptions

Returns

Listing<User>


getBannedUsers

getBannedUsers(options?): Listing<User>

Parameters

NameType
optionsGetUsersOptions

Returns

Listing<User>


getBannedWikiContributors

getBannedWikiContributors(options?): Listing<User>

Parameters

NameType
optionsGetUsersOptions

Returns

Listing<User>


getCommentsAndPostsByIds

getCommentsAndPostsByIds(ids): Listing<Post | Comment>

Return a listing of things specified by their fullnames.

Parameters

NameTypeDescription
idsstring[]Array of thing full ids (e.g. t3_abc123)

Returns

Listing<Post | Comment>

Example

const subreddit = await reddit.getSubredditByName('askReddit');
const listing = subreddit.getCommentsAndPostsByIds(['t3_abc123', 't1_xyz123']);
const items = await listing.all();
console.log(items); // [Post, Comment]

getControversialPosts

getControversialPosts(options?): Listing<Post>

Parameters

NameType
optionsOmit<GetPostsOptionsWithTimeframe, "subredditName">

Returns

Listing<Post>


getEdited

getEdited(options): Listing<Comment>

Return a listing of things that have been edited recently.

Parameters

NameType
optionsAboutSubredditOptions<"comment">

Returns

Listing<Comment>

Example

const subreddit = await reddit.getSubredditByName('mysubreddit');
let listing = await subreddit.getEdited();
console.log('Posts and Comments: ', await listing.all());
listing = await subreddit.getEdited({ type: 'post' });
console.log('Posts: ', await listing.all());

getEdited(options): Listing<Post>

Parameters

NameType
optionsAboutSubredditOptions<"post">

Returns

Listing<Post>

getEdited(options?): Listing<Post | Comment>

Parameters

NameType
options?AboutSubredditOptions<"all">

Returns

Listing<Post | Comment>


getModQueue

getModQueue(options): Listing<Comment>

Return a listing of things requiring moderator review, such as reported things and items.

Parameters

NameType
optionsAboutSubredditOptions<"comment">

Returns

Listing<Comment>

Example

const subreddit = await reddit.getSubredditByName('mysubreddit');
let listing = await subreddit.getModQueue();
console.log('Posts and Comments: ', await listing.all());
listing = await subreddit.getModQueue({ type: 'post' });
console.log('Posts: ', await listing.all());

getModQueue(options): Listing<Post>

Parameters

NameType
optionsAboutSubredditOptions<"post">

Returns

Listing<Post>

getModQueue(options?): Listing<Post | Comment>

Parameters

NameType
options?AboutSubredditOptions<"all">

Returns

Listing<Post | Comment>


getModerationLog

getModerationLog(options): Listing<ModAction>

Parameters

NameType
optionsGetModerationLogOptions

Returns

Listing<ModAction>


getModerators

getModerators(options?): Listing<User>

Parameters

NameType
optionsGetUsersOptions

Returns

Listing<User>


getMutedUsers

getMutedUsers(options?): Listing<User>

Parameters

NameType
optionsGetUsersOptions

Returns

Listing<User>


getPostFlairTemplates

getPostFlairTemplates(): Promise<FlairTemplate[]>

Returns

Promise<FlairTemplate[]>


getReports

getReports(options): Listing<Comment>

Return a listing of things that have been reported.

Parameters

NameType
optionsAboutSubredditOptions<"comment">

Returns

Listing<Comment>

Example

const subreddit = await reddit.getSubredditByName('mysubreddit');
let listing = await subreddit.getReports();
console.log('Posts and Comments: ', await listing.all());
listing = await subreddit.getReports({ type: 'post' });
console.log('Posts: ', await listing.all());

getReports(options): Listing<Post>

Parameters

NameType
optionsAboutSubredditOptions<"post">

Returns

Listing<Post>

getReports(options?): Listing<Post | Comment>

Parameters

NameType
options?AboutSubredditOptions<"all">

Returns

Listing<Post | Comment>


getSpam

getSpam(options): Listing<Comment>

Return a listing of things that have been marked as spam or otherwise removed.

Parameters

NameType
optionsAboutSubredditOptions<"comment">

Returns

Listing<Comment>

Example

const subreddit = await reddit.getSubredditByName('mysubreddit');
let listing = await subreddit.getSpam();
console.log('Posts and Comments: ', await listing.all());
listing = await subreddit.getSpam({ type: 'post' });
console.log('Posts: ', await listing.all());

getSpam(options): Listing<Post>

Parameters

NameType
optionsAboutSubredditOptions<"post">

Returns

Listing<Post>

getSpam(options?): Listing<Post | Comment>

Parameters

NameType
options?AboutSubredditOptions<"all">

Returns

Listing<Post | Comment>


getTopPosts

getTopPosts(options?): Listing<Post>

Parameters

NameType
optionsOmit<GetPostsOptionsWithTimeframe, "subredditName">

Returns

Listing<Post>


getUnmoderated

getUnmoderated(options): Listing<Comment>

Return a listing of things that have yet to be approved/removed by a mod.

Parameters

NameType
optionsAboutSubredditOptions<"comment">

Returns

Listing<Comment>

Example

const subreddit = await reddit.getSubredditByName('mysubreddit');
let listing = await subreddit.getUnmoderated();
console.log('Posts and Comments: ', await listing.all());
listing = await subreddit.getUnmoderated({ type: 'post' });
console.log('Posts: ', await listing.all());

getUnmoderated(options): Listing<Post>

Parameters

NameType
optionsAboutSubredditOptions<"post">

Returns

Listing<Post>

getUnmoderated(options?): Listing<Post | Comment>

Parameters

NameType
options?AboutSubredditOptions<"all">

Returns

Listing<Post | Comment>


getUserFlair

getUserFlair(options?): Promise<GetUserFlairBySubredditResponse>

Get the user flair for the given subreddit. If usernames is provided then it will return only the flair for the specified users. If retrieving the list of flair for a given subreddit and the list is long then this method will return a next field which can be passed into the after field on the next call to retrieve the next slice of data. To retrieve the previous slice of data pass the prev field into the before field during the subsequent call.

Parameters

NameTypeDescription
options?GetUserFlairOptionsSee interface

Returns

Promise<GetUserFlairBySubredditResponse>

Example

const subredditName = 'mysubreddit';
const subreddit = await reddit.getSubredditByName(subredditName);
const response = await subreddit.getUserFlair();
const userFlairList = response.users;

Example

const response = await subreddit.getUserFlair({ after: 't2_awefae' });
const userFlairList = response.users;

Example

const response = await subreddit.getUserFlair({ usernames: ['toxictoad', 'badapple'] });
const userFlairList = response.users;

getUserFlairTemplates

getUserFlairTemplates(): Promise<FlairTemplate[]>

Returns

Promise<FlairTemplate[]>


getWikiContributors

getWikiContributors(options?): Listing<User>

Parameters

NameType
optionsGetUsersOptions

Returns

Listing<User>


inviteModerator

inviteModerator(username, permissions?): Promise<void>

Parameters

NameType
usernamestring
permissions?ModeratorPermission[]

Returns

Promise<void>


muteUser

muteUser(username, note?): Promise<void>

Parameters

NameType
usernamestring
note?string

Returns

Promise<void>


removeModerator

removeModerator(username): Promise<void>

Parameters

NameType
usernamestring

Returns

Promise<void>


removeUser

removeUser(username): Promise<void>

Parameters

NameType
usernamestring

Returns

Promise<void>


removeWikiContributor

removeWikiContributor(username): Promise<void>

Parameters

NameType
usernamestring

Returns

Promise<void>


revokeModeratorInvite

revokeModeratorInvite(username): Promise<void>

Parameters

NameType
usernamestring

Returns

Promise<void>


setModeratorPermissions

setModeratorPermissions(username, permissions): Promise<void>

Parameters

NameType
usernamestring
permissionsModeratorPermission[]

Returns

Promise<void>


submitPost

submitPost(options): Promise<Post>

Parameters

NameType
optionsSubmitLinkOptions | SubmitSelfPostOptions

Returns

Promise<Post>


toJSON

toJSON(): Pick<Subreddit, "description" | "type" | "id" | "name" | "title" | "settings" | "language" | "nsfw" | "createdAt" | "numberOfSubscribers" | "numberOfActiveUsers">

Returns

Pick<Subreddit, "description" | "type" | "id" | "name" | "title" | "settings" | "language" | "nsfw" | "createdAt" | "numberOfSubscribers" | "numberOfActiveUsers">


unbanUser

unbanUser(username): Promise<void>

Parameters

NameType
usernamestring

Returns

Promise<void>


unbanWikiContributor

unbanWikiContributor(username): Promise<void>

Parameters

NameType
usernamestring

Returns

Promise<void>


unmuteUser

unmuteUser(username): Promise<void>

Parameters

NameType
usernamestring

Returns

Promise<void>

  • Table of contents
  • Accessors
    • createdAt
    • description
    • id
    • language
    • name
    • nsfw
    • numberOfActiveUsers
    • numberOfSubscribers
    • permalink
    • postFlairsEnabled
    • settings
    • title
    • type
    • url
    • userFlairsEnabled
    • usersCanAssignPostFlairs
    • usersCanAssignUserFlairs
  • Methods
    • addWikiContributor
    • approveUser
    • banUser
    • banWikiContributor
    • createPostFlairTemplate
    • createUserFlairTemplate
    • getApprovedUsers
    • getBannedUsers
    • getBannedWikiContributors
    • getCommentsAndPostsByIds
    • getControversialPosts
    • getEdited
    • getModQueue
    • getModerationLog
    • getModerators
    • getMutedUsers
    • getPostFlairTemplates
    • getReports
    • getSpam
    • getTopPosts
    • getUnmoderated
    • getUserFlair
    • getUserFlairTemplates
    • getWikiContributors
    • inviteModerator
    • muteUser
    • removeModerator
    • removeUser
    • removeWikiContributor
    • revokeModeratorInvite
    • setModeratorPermissions
    • submitPost
    • toJSON
    • unbanUser
    • unbanWikiContributor
    • unmuteUser