Skip to main content
Version: Next

Subreddit

@devvit/public-api v0.12.14-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(): undefined | string

The description of the subreddit.

Returns

undefined | string


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(): undefined | string

The title of the subreddit.

Returns

undefined | string


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

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>


createUserFlairTemplate()

createUserFlairTemplate(options): Promise<FlairTemplate>

Parameters

options

Omit<CreateFlairTemplateOptions, "subredditName">

Returns

Promise<FlairTemplate>


getApprovedUsers()

getApprovedUsers(options): Listing<User>

Parameters

options

GetUsersOptions = {}

Returns

Listing<User>


getBannedUsers()

getBannedUsers(options): Listing<User>

Parameters

options

GetUsersOptions = {}

Returns

Listing<User>


getBannedWikiContributors()

getBannedWikiContributors(options): Listing<User>

Parameters

options

GetUsersOptions = {}

Returns

Listing<User>


getCommentsAndPostsByIds()

getCommentsAndPostsByIds(ids): Listing<Post | Comment>

Return a listing of things specified by their fullnames.

Parameters

ids

string[]

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

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<Post | Comment>

Return a listing of things that have been edited recently.

Parameters
options?

AboutSubredditOptions<"all">

Returns

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

getModerationLog()

getModerationLog(options): Listing<ModAction>

Parameters

options

GetModerationLogOptions

Returns

Listing<ModAction>


getModerators()

getModerators(options): Listing<User>

Parameters

options

GetUsersOptions = {}

Returns

Listing<User>


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<Post | Comment>

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

Parameters
options?

AboutSubredditOptions<"all">

Returns

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

getMutedUsers()

getMutedUsers(options): Listing<User>

Parameters

options

GetUsersOptions = {}

Returns

Listing<User>


getPostFlairTemplates()

getPostFlairTemplates(): Promise<FlairTemplate[]>

Returns

Promise<FlairTemplate[]>


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<Post | Comment>

Return a listing of things that have been reported.

Parameters
options?

AboutSubredditOptions<"all">

Returns

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

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<Post | Comment>

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

Parameters
options?

AboutSubredditOptions<"all">

Returns

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

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<Post | Comment>

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

Parameters
options?

AboutSubredditOptions<"all">

Returns

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

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<User>

Parameters

options

GetUsersOptions = {}

Returns

Listing<User>


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>


revokeModeratorInvite()

revokeModeratorInvite(username): Promise<void>

Parameters

username

string

Returns

Promise<void>


setModeratorPermissions()

setModeratorPermissions(username, permissions): Promise<void>

Parameters

username

string

permissions

ModeratorPermission[]

Returns

Promise<void>


submitPost()

submitPost(options): Promise<Post>

Parameters

options

SubmitLinkOptions | SubmitSelfPostOptions

Returns

Promise<Post>


toJSON()

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

Returns

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


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>