Skip to main content

Subreddit

@devvit/reddit v0.15.5-dev


Class: Subreddit

A class representing a subreddit.

Accessors​

createdAt​

Get Signature​

get createdAt(): Date

The creation date of the subreddit.

Returns​

Date


description​

Get Signature​

get description(): string | undefined

The description of the subreddit. Appears in the sidebar of the subreddit.

Returns​

string | undefined


id​

Get Signature​

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

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

Returns​

`t5_${string}`


language​

Get Signature​

get language(): string

The language of the subreddit.

Returns​

string


name​

Get Signature​

get name(): string

The name of a subreddit omitting the r/.

Returns​

string


nsfw​

Get Signature​

get nsfw(): boolean

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

Returns​

boolean


numberOfActiveUsers​

Get Signature​

get numberOfActiveUsers(): number

The number of active users of the subreddit.

Returns​

number


numberOfSubscribers​

Get Signature​

get numberOfSubscribers(): number

The number of subscribers of the subreddit.

Returns​

number


Get Signature​

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 Signature​

get postFlairsEnabled(): boolean

Whether the post flairs are enabled for this subreddit.

Returns​

boolean


settings​

Get Signature​

get settings(): SubredditSettings

The settings of the subreddit.

Returns​

SubredditSettings


title​

Get Signature​

get title(): string | undefined

The title of the subreddit.

Returns​

string | undefined


type​

Get Signature​

get type(): SubredditType

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

Returns​

SubredditType


url​

Get Signature​

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 Signature​

get userFlairsEnabled(): boolean

Whether the user flairs are enabled for this subreddit.

Returns​

boolean


usersCanAssignPostFlairs​

Get Signature​

get usersCanAssignPostFlairs(): boolean

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

Returns​

boolean


usersCanAssignUserFlairs​

Get Signature​

get usersCanAssignUserFlairs(): boolean

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

Returns​

boolean

Methods​

addRemovalReason()​

addRemovalReason(options): Promise<string>

Add a removal reason to this subreddit.

Parameters​

options​
message​

string

The message associated with the removal reason.

title​

string

The title of the removal reason.

Returns​

Promise<string>

The new removal reason ID.


addWikiContributor()​

addWikiContributor(username): Promise<void>

Parameters​

username​

string

Returns​

Promise<void>


approveUser()​

approveUser(username): Promise<void>

Parameters​

username​

string

Returns​

Promise<void>


banUser()​

banUser(options): Promise<void>

Parameters​

options​

Omit<BanUserOptions, "subredditName">

Returns​

Promise<void>


banWikiContributor()​

banWikiContributor(options): Promise<void>

Parameters​

options​

Omit<BanWikiContributorOptions, "subredditName">

Returns​

Promise<void>


createPostFlairTemplate()​

createPostFlairTemplate(options): Promise<FlairTemplate>

Parameters​

options​

Omit<CreateFlairTemplateOptions, "subredditName">

Returns​

Promise<FlairTemplate>


createRule()​

createRule(options): Promise<void>

Create a new subreddit rule.

Parameters​

options​

Readonly<CreateRuleOptions>

Options for creating a new subreddit rule.

Returns​

Promise<void>


createUserFlairTemplate()​

createUserFlairTemplate(options): Promise<FlairTemplate>

Parameters​

options​

Omit<CreateFlairTemplateOptions, "subredditName">

Returns​

Promise<FlairTemplate>


crosspost()​

crosspost(opts): Promise<Post>

Parameters​

opts​

Readonly<CrosspostOptions>

Returns​

Promise<Post>


deleteRemovalReason()​

deleteRemovalReason(reasonId): Promise<void>

Delete a removal reason from this subreddit.

Parameters​

reasonId​

string

Returns​

Promise<void>


getApprovedUsers()​

getApprovedUsers(options?): Listing<SubredditContributorUser>

Parameters​

options?​

GetUsersOptions = {}

Returns​

Listing<SubredditContributorUser>


getBannedUsers()​

getBannedUsers(options?): Listing<SubredditBannedUser>

Parameters​

options?​

GetUsersOptions = {}

Returns​

Listing<SubredditBannedUser>


getBannedWikiContributors()​

getBannedWikiContributors(options?): Listing<SubredditWikiBannedUser>

Parameters​

options?​

GetUsersOptions = {}

Returns​

Listing<SubredditWikiBannedUser>


getCommentsAndPostsByIds()​

getCommentsAndPostsByIds(ids): Listing<Comment | Post>

Return a listing of things specified by their fullnames.

Parameters​

ids​

string[]

Array of thing full ids (e.g. t3_abc123)

Returns​

Listing<Comment | Post>

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​

options?​

Omit<GetPostsOptionsWithTimeframe, "subredditName"> = {}

Returns​

Listing<Post>


getEdited()​

Call Signature​

getEdited(options): Listing<Comment>

Return a listing of things that have been edited recently.

Parameters​
options​

AboutSubredditOptions<"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())

Call Signature​

getEdited(options): Listing<Post>

Return a listing of things that have been edited recently.

Parameters​
options​

AboutSubredditOptions<"post">

Returns​

Listing<Post>

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

Call Signature​

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

Return a listing of things that have been edited recently.

Parameters​
options?​

AboutSubredditOptions<"all">

Returns​

Listing<Comment | Post>

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

getHighlightedPosts()​

getHighlightedPosts(): Promise<HighlightedPostInfo[]>

Returns this subreddit's community highlights in display order.

Returns​

Promise<HighlightedPostInfo[]>

Example​

const highlightedPosts = await subreddit.getHighlightedPosts();

getModerationLog()​

getModerationLog(options): Listing<ModAction>

Parameters​

options​

GetModerationLogOptions

Returns​

Listing<ModAction>


getModerators()​

getModerators(options?): Listing<SubredditModeratorUser>

Parameters​

options?​

GetUsersOptions = {}

Returns​

Listing<SubredditModeratorUser>


getModQueue()​

Call Signature​

getModQueue(options): Listing<Comment>

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

Parameters​
options​

AboutSubredditOptions<"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())

Call Signature​

getModQueue(options): Listing<Post>

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

Parameters​
options​

AboutSubredditOptions<"post">

Returns​

Listing<Post>

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

Call Signature​

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

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

Parameters​
options?​

AboutSubredditOptions<"all">

Returns​

Listing<Comment | Post>

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

getMutedUsers()​

getMutedUsers(options?): Listing<SubredditMutedUser>

Parameters​

options?​

GetUsersOptions = {}

Returns​

Listing<SubredditMutedUser>


getPostFlairTemplates()​

getPostFlairTemplates(): Promise<FlairTemplate[]>

Returns​

Promise<FlairTemplate[]>


getRemovalReasons()​

getRemovalReasons(): Promise<RemovalReason[]>

Get the list of this subreddit's removal reasons (ordered).

Returns​

Promise<RemovalReason[]>


getReports()​

Call Signature​

getReports(options): Listing<Comment>

Return a listing of things that have been reported.

Parameters​
options​

AboutSubredditOptions<"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())

Call Signature​

getReports(options): Listing<Post>

Return a listing of things that have been reported.

Parameters​
options​

AboutSubredditOptions<"post">

Returns​

Listing<Post>

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

Call Signature​

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

Return a listing of things that have been reported.

Parameters​
options?​

AboutSubredditOptions<"all">

Returns​

Listing<Comment | Post>

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

getRules()​

getRules(): Promise<Rule[]>

Returns​

Promise<Rule[]>


getSpam()​

Call Signature​

getSpam(options): Listing<Comment>

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

Parameters​
options​

AboutSubredditOptions<"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())

Call Signature​

getSpam(options): Listing<Post>

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

Parameters​
options​

AboutSubredditOptions<"post">

Returns​

Listing<Post>

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

Call Signature​

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

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

Parameters​
options?​

AboutSubredditOptions<"all">

Returns​

Listing<Comment | Post>

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

getTopPosts()​

getTopPosts(options?): Listing<Post>

Parameters​

options?​

Omit<GetPostsOptionsWithTimeframe, "subredditName"> = {}

Returns​

Listing<Post>


getUnmoderated()​

Call Signature​

getUnmoderated(options): Listing<Comment>

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

Parameters​
options​

AboutSubredditOptions<"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())

Call Signature​

getUnmoderated(options): Listing<Post>

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

Parameters​
options​

AboutSubredditOptions<"post">

Returns​

Listing<Post>

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

Call Signature​

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

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

Parameters​
options?​

AboutSubredditOptions<"all">

Returns​

Listing<Comment | Post>

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

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​

options?​

GetUserFlairOptions

See interface

Returns​

Promise<GetUserFlairBySubredditResponse>

Examples​

const subredditName = "mysubreddit"
const subreddit = await reddit.getSubredditByName(subredditName)
const response = await subreddit.getUserFlair();
const userFlairList = response.users
const response = await subreddit.getUserFlair({ after: "t2_awefae"});
const userFlairList = response.users
const response = await subreddit.getUserFlair({ usernames: ['toxictoad', 'badapple']});
const userFlairList = response.users

getUserFlairTemplates()​

getUserFlairTemplates(): Promise<FlairTemplate[]>

Returns​

Promise<FlairTemplate[]>


getWikiContributors()​

getWikiContributors(options?): Listing<SubredditWikiContributorUser>

Parameters​

options?​

GetUsersOptions = {}

Returns​

Listing<SubredditWikiContributorUser>


inviteModerator()​

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

Parameters​

username​

string

permissions?​

ModeratorPermission[]

Returns​

Promise<void>


muteUser()​

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

Parameters​

username​

string

note?​

string

Returns​

Promise<void>


removeModerator()​

removeModerator(username): Promise<void>

Parameters​

username​

string

Returns​

Promise<void>


removeUser()​

removeUser(username): Promise<void>

Parameters​

username​

string

Returns​

Promise<void>


removeWikiContributor()​

removeWikiContributor(username): Promise<void>

Parameters​

username​

string

Returns​

Promise<void>


reorderHighlightedPosts()​

reorderHighlightedPosts(postIds): Promise<void>

Reorders this subreddit's community highlights.

Parameters​

postIds​

readonly `t3_${string}`[]

Highlighted post IDs in their new display order.

Returns​

Promise<void>

Example​

const highlights = await subreddit.getHighlightedPosts();
await subreddit.reorderHighlightedPosts(highlights.map(({ postId }) => postId).reverse());

reorderRules()​

reorderRules(rules): Promise<void>

Parameters​

rules​

Rule[]

Returns​

Promise<void>


revokeModeratorInvite()​

revokeModeratorInvite(username): Promise<void>

Parameters​

username​

string

Returns​

Promise<void>


searchPosts()​

searchPosts(options): Listing<Post>

Search for posts in this subreddit.

Parameters​

options​

Omit<SearchPostsOptions, "subredditName">

Returns​

Listing<Post>


setModeratorPermissions()​

setModeratorPermissions(username, permissions): Promise<void>

Parameters​

username​

string

permissions​

ModeratorPermission[]

Returns​

Promise<void>


submitCustomPost()​

submitCustomPost(opts): Promise<Post>

Parameters​

opts​

Readonly<SubmitCustomPostOptions>

Returns​

Promise<Post>


submitPost()​

submitPost(opts): Promise<Post>

Parameters​

opts​

Readonly<SubmitPostOptions>

Returns​

Promise<Post>


toJSON()​

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

Returns​

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


unbanUser()​

unbanUser(username): Promise<void>

Parameters​

username​

string

Returns​

Promise<void>


unbanWikiContributor()​

unbanWikiContributor(username): Promise<void>

Parameters​

username​

string

Returns​

Promise<void>


unmuteUser()​

unmuteUser(username): Promise<void>

Parameters​

username​

string

Returns​

Promise<void>


updateRemovalReason()​

updateRemovalReason(reasonId, options): Promise<void>

Update a removal reason's title and message in this subreddit.

Parameters​

reasonId​

string

options​
message​

string

title​

string

Returns​

Promise<void>


updateSettings()​

updateSettings(options): Promise<void>

Updates subreddit settings via the SiteAdmin API. Current settings are used as the base; only fields specified in options are changed. In order to reset a field to its default value, pass the default value as the option value.

Parameters​

options​

SubredditSettingsOptions

Optional settings to apply. Omitted fields are left unchanged.

Returns​

Promise<void>

Example​

const subreddit = await reddit.getSubredditByName('mysubreddit');
await subreddit.setSettings({ restrictPosting: true, allowImages: false });
await subreddit.setSettings({ type: 'restricted', title: 'New Title', description: 'Sidebar text' });

getSubscribedSubredditsForCurrentUser()​

static getSubscribedSubredditsForCurrentUser(options?): Listing<Subreddit>

Parameters​

options?​

GetSubscribedSubredditsForCurrentUserOptions = {}

Returns​

Listing<Subreddit>