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
permalink
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
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
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()
Parameters
options
GetUsersOptions = {}
Returns
getBannedUsers()
Parameters
options
GetUsersOptions = {}
Returns
getBannedWikiContributors()
Parameters
options
GetUsersOptions = {}
Returns
getCommentsAndPostsByIds()
Return a listing of things specified by their fullnames.
Parameters
ids
string[]
Array of thing full ids (e.g. t3_abc123)
Returns
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()
Parameters
options
Omit<GetPostsOptionsWithTimeframe, "subredditName"> = {}
Returns
getEdited()
Call Signature
Return a listing of things that have been edited recently.
Parameters
options
AboutSubredditOptions<"comment">
Returns
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
Return a listing of things that have been edited recently.
Parameters
options
AboutSubredditOptions<"post">
Returns
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
Return a listing of things that have been edited recently.
Parameters
options?
AboutSubredditOptions<"all">
Returns
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()
Parameters
options
GetModerationLogOptions
Returns
getModerators()
Parameters
options
GetUsersOptions = {}
Returns
getModQueue()
Call Signature
Return a listing of things requiring moderator review, such as reported things and items.
Parameters
options
AboutSubredditOptions<"comment">
Returns
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
Return a listing of things requiring moderator review, such as reported things and items.
Parameters
options
AboutSubredditOptions<"post">
Returns
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
Return a listing of things requiring moderator review, such as reported things and items.
Parameters
options?
AboutSubredditOptions<"all">
Returns
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()
Parameters
options
GetUsersOptions = {}
Returns
getPostFlairTemplates()
getPostFlairTemplates():
Promise<FlairTemplate[]>
Returns
Promise<FlairTemplate[]>
getReports()
Call Signature
Return a listing of things that have been reported.
Parameters
options
AboutSubredditOptions<"comment">
Returns
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
Return a listing of things that have been reported.
Parameters
options
AboutSubredditOptions<"post">
Returns
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
Return a listing of things that have been reported.
Parameters
options?
AboutSubredditOptions<"all">
Returns
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
Return a listing of things that have been marked as spam or otherwise removed.
Parameters
options
AboutSubredditOptions<"comment">
Returns
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
Return a listing of things that have been marked as spam or otherwise removed.
Parameters
options
AboutSubredditOptions<"post">
Returns
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
Return a listing of things that have been marked as spam or otherwise removed.
Parameters
options?
AboutSubredditOptions<"all">
Returns
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()
Parameters
options
Omit<GetPostsOptionsWithTimeframe, "subredditName"> = {}
Returns
getUnmoderated()
Call Signature
Return a listing of things that have yet to be approved/removed by a mod.
Parameters
options
AboutSubredditOptions<"comment">
Returns
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
Return a listing of things that have yet to be approved/removed by a mod.
Parameters
options
AboutSubredditOptions<"post">
Returns
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
Return a listing of things that have yet to be approved/removed by a mod.
Parameters
options?
AboutSubredditOptions<"all">
Returns
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?
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()
Parameters
options
GetUsersOptions = {}
Returns
inviteModerator()
inviteModerator(
username,permissions?):Promise<void>
Parameters
username
string
permissions?
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
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>