Skip to main content

Post

@devvit/reddit v0.15.5-dev


Class: Post

Accessors​

approved​

Get Signature​

get approved(): boolean

Whether the post has been approved by a moderator.

Returns​

boolean


approvedAtUtc​

Get Signature​

get approvedAtUtc(): number

The moderation approval time as Unix seconds, or 0 when unavailable.

Use approved to check the current approval state. Convert a nonzero value to a Date with new Date(post.approvedAtUtc * 1000).

Returns​

number


archived​

Get Signature​

get archived(): boolean

Whether the post is archived.

Returns​

boolean


authorFlair​

Get Signature​

get authorFlair(): CommonFlair | undefined

The author's subreddit flair, or undefined when unavailable.

Returns​

CommonFlair | undefined


authorId​

Get Signature​

get authorId(): `t2_${string}` | undefined

The creator's account identifier, or undefined when unavailable.

Returns​

`t2_${string}` | undefined


authorName​

Get Signature​

get authorName(): string

The creator's username without the leading u/.

Returns​

string


bannedAtUtc​

Get Signature​

get bannedAtUtc(): number

The ban time as Unix seconds, or 0 when unavailable.

Convert a nonzero value to a Date with new Date(post.bannedAtUtc * 1000).

Returns​

number


body​

Get Signature​

get body(): string | undefined

The post body in Markdown. undefined if absent.

Returns​

string | undefined


bodyHtml​

Get Signature​

get bodyHtml(): string | undefined

The post body rendered as HTML, or undefined when unavailable.

Returns​

string | undefined


comments​

Get Signature​

get comments(): Listing<Comment>

A listing of the post's top-level comments. Each comment exposes its replies separately.

Example​
const comments = await post.comments.get(25);
Returns​

Listing<Comment>


createdAt​

Get Signature​

get createdAt(): Date

The date when the post was created.

Returns​

Date


crosspostParentId​

Get Signature​

get crosspostParentId(): `t3_${string}` | undefined

The original post's identifier when this post is a crosspost. undefined if not a crosspost or parent is unavailable.

Returns​

`t3_${string}` | undefined


distinguishedBy​

Get Signature​

get distinguishedBy(): string | undefined

The post's distinction category.

For example, a post distinguished by a moderator or employee returns "moderator" or "admin". undefined means no distinction is available.

Returns​

string | undefined


edited​

Get Signature​

get edited(): boolean

Whether the post body has been edited since it was created.

Returns​

boolean


flair​

Get Signature​

get flair(): CommonFlair | undefined

The post flair, or undefined when unavailable.

Returns​

CommonFlair | undefined


Get Signature​

get gallery(): GalleryMedia[]

Get the image or GIF metadata in the post. Empty if the post doesn't have any media.

Gallery posts can contain multiple entries. For other posts, one entry from the first preview image or GIF variant.

Returns​

GalleryMedia[]


hidden​

Get Signature​

get hidden(): boolean

Whether the post is hidden from listings.

Returns​

boolean


id​

Get Signature​

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

Returns​

`t3_${string}`


ignoringReports​

Get Signature​

get ignoringReports(): boolean

Whether reports on the post are being ignored.

Returns​

boolean


locked​

Get Signature​

get locked(): boolean

Whether the post is locked and new comments are disabled.

Returns​

boolean


modReportReasons​

Get Signature​

get modReportReasons(): string[]

Deprecated​

Use modReports to retain each report's author.

Returns​

string[]


modReports​

Get Signature​

get modReports(): ModeratorReport[]

Moderator reports and authors, or an empty array when unavailable.

Returns​

ModeratorReport[]


nsfw​

Get Signature​

get nsfw(): boolean

Whether the post is marked not safe for work (NSFW).

Returns​

boolean


numberOfComments​

Get Signature​

get numberOfComments(): number

The number of comments, or 0 when none are available.

Returns​

number


numberOfReports​

Get Signature​

get numberOfReports(): number

The number of reports, or 0 when none are available.

Returns​

number


Get Signature​

get permalink(): string

The post's path relative to https://www.reddit.com.

Example​
"/r/wallstreetbets/comments/abc123/post/"
Returns​

string


pollData​

Get Signature​

get pollData(): PollData | undefined

The post's poll options, vote totals, and voting end time. undefined if the post is not a poll.

Returns​

PollData | undefined


quarantined​

Get Signature​

get quarantined(): boolean

Whether the post is quarantined.

Returns​

boolean


removed​

Get Signature​

get removed(): boolean

Whether the post has been removed by a moderator.

Returns​

boolean


removedBy​

Get Signature​

get removedBy(): string | undefined

The username of the account that removed the post, without the leading u/, or undefined when unavailable.

Returns​

string | undefined


removedByCategory​

Get Signature​

get removedByCategory(): string | undefined

Identifies who or what removed the post:

  • "anti_evil_ops": Reddit Anti-Evil Operations.
  • "author": The post's author.
  • "automod_filtered": AutoModerator filtering.
  • "community_ops": Reddit Community Operations.
  • "content_takedown": A content-policy takedown.
  • "copyright_takedown": A copyright takedown.
  • "deleted": The post was deleted.
  • "moderator": A subreddit moderator.
  • "reddit": Any other remover.
  • undefined: No removal category is available.
Returns​

string | undefined


score​

Get Signature​

get score(): number

The post's upvotes minus downvotes, or 0 when unavailable.

Returns​

number


secureMedia​

Get Signature​

get secureMedia(): SecureMedia | undefined

Metadata for embedded or Reddit-hosted media, including oEmbed or Reddit video data.

Returns undefined when the post has no secure media metadata.

Returns​

SecureMedia | undefined


spam​

Get Signature​

get spam(): boolean

Whether the post has been marked as spam by a moderator.

Returns​

boolean


spoiler​

Get Signature​

get spoiler(): boolean

Whether the post's content is hidden until the user explicitly opens it.

Returns​

boolean


stickied​

Get Signature​

get stickied(): boolean

Whether the post is presented before other posts in its subreddit.

Returns​

boolean


subredditId​

Get Signature​

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

The subreddit identifier where the post was created.

Returns​

`t5_${string}`


subredditName​

Get Signature​

get subredditName(): string

The owning subreddit's name without the leading r/.

Returns​

string


thumbnail​

Get Signature​

get thumbnail(): { height: number; url: string; width: number; } | undefined

The post's preview thumbnail URL and dimensions in pixels.

undefined means no thumbnail is available or the source field contains a placeholder such as "self" or "nsfw".

Returns​

{ height: number; url: string; width: number; } | undefined


title​

Get Signature​

get title(): string

The title displayed for the post.

Returns​

string


url​

Get Signature​

get url(): string

The post URL.

This is the submitted URL for a link post or the full-size media URL for an image or video post. Use permalink for the relative path.

Example​
"https://www.reddit.com/r/wallstreetbets/comments/abc123/post/"
Returns​

string


userReportReasons​

Get Signature​

get userReportReasons(): string[]

User report reasons, or an empty array when none are available.

Returns​

string[]

Methods​

addComment()​

addComment(opts): Promise<Comment>

Creates a top-level comment on the post.

Parameters​

opts​

Readonly<CommentSubmissionOptions>

Returns​

Promise<Comment>


addRemovalNote()​

addRemovalNote(opts): Promise<void>

Adds a moderator note explaining why the post was removed.

Parameters​

opts​

Readonly<Omit<AddRemovalNoteOptions, "itemIds">>

Returns​

Promise<void>


approve()​

approve(): Promise<void>

Approves the post and updates this instance's moderation state.

Returns​

Promise<void>


crosspost()​

crosspost(opts): Promise<Post>

Creates a crosspost of this post in another subreddit.

Parameters​

opts​

Readonly<Omit<CrosspostOptions, "postId">>

Returns​

Promise<Post>


delete()​

delete(): Promise<void>

Deletes the post as the app account.

Returns​

Promise<void>


distinguish()​

distinguish(): Promise<void>

Distinguishes the post as a moderator and updates this instance.

Returns​

Promise<void>


distinguishAsAdmin()​

distinguishAsAdmin(): Promise<void>

Distinguishes the post as an administrator and updates this instance.

Returns​

Promise<void>


edit()​

edit(opts): Promise<void>

Replaces the post body as the app account, then updates the cached body and edited state from the response.

Parameters​

opts​

Readonly<PostTextOptions>

Returns​

Promise<void>


filter()​

filter(options?): Promise<void>

Experimental

Filters a post. When a post is filtered, it is added to the ModQueue for review. By default, filtered posts are hidden while in the queue. Set keep to true to keep the post visible. Set reason to show moderators a reason; when keep is true, the reason is also shown on the post.

Parameters​

options?​

FilterOptions

Returns​

Promise<void>


getAuthor()​

getAuthor(): Promise<User | undefined>

Fetches the creator's account, or undefined if it is unavailable.

Returns​

Promise<User | undefined>


getCurrentUserPollOption()​

getCurrentUserPollOption(): Promise<PollOption | undefined>

Get the poll option the authenticated user selected for this post. Returns undefined if the post is not a poll or the user has not voted.

This method will get the poll option for the app account by default. To get the poll option for a user, please contact Reddit.

Returns​

Promise<PollOption | undefined>


getCustomPostStyles()​

getCustomPostStyles(): Promise<StrictRequired<CustomPostStylesInput>>

Experimental

Get the custom styles for a custom post.

Returns​

Promise<StrictRequired<CustomPostStylesInput>>


getDuplicates()​

getDuplicates(opts?): Listing<Post>

A listing of other posts that reference the same URL.

Parameters​

opts?​

Omit<GetDuplicatesOptions, "postId"> = {}

Returns​

Listing<Post>

Example​

const duplicates = await post.getDuplicates().get(25);

getEnrichedThumbnail()​

getEnrichedThumbnail(): Promise<EnrichedThumbnail | undefined>

Get a thumbnail that contains a preview image and also contains a blurred preview for NSFW images. The thumbnail returned has higher resolution than Post.thumbnail. Returns undefined if the post doesn't have a thumbnail

Returns​

Promise<EnrichedThumbnail | undefined>

Throws​

Throws an error if the thumbnail could not be fetched

Example​

// from a menu action, form, scheduler, trigger, custom post click event, etc
const post = await context.reddit.getPostById(context.postId);
const enrichedThumbnail = await post.getEnrichedThumbnail();

getPostData()​

getPostData(): Promise<JsonObject | undefined>

Get the post data for the custom post.

Returns​

Promise<JsonObject | undefined>

Example​

const post = await reddit.getPostById(context.postId);
const postData = await post.getPostData();

hide()​

hide(): Promise<void>

Hides the post from the app account and updates this instance.

Returns​

Promise<void>


highlight()​

highlight(options?): Promise<void>

Adds this post to its subreddit's community highlights, or updates its highlight settings if it is already highlighted.

Note: a subreddit can have up to six highlights at a time. Highlighting a seventh post will remove the last post in Subreddit.getHighlightedPosts() from the highlights.

Parameters​

options?​

Readonly<HighlightPostOptions>

Optional expiration and label settings.

Returns​

Promise<void>

Example​

await post.highlight({
highlightUntil: new Date('2030-01-01T00:00:00Z'),
highlightLabelType: 'ANNOUNCEMENT',
});

ignoreReports()​

ignoreReports(): Promise<void>

Ignores reports and updates this instance's report-ignore state.

Returns​

Promise<void>


isApproved()​

isApproved(): boolean

The post's approval state.

Returns​

boolean


isArchived()​

isArchived(): boolean

The post's archived state.

Returns​

boolean


isDistinguishedBy()​

isDistinguishedBy(): string | undefined

The post's distinction category.

Returns​

string | undefined


isEdited()​

isEdited(): boolean

The post's edited state.

Returns​

boolean


isHidden()​

isHidden(): boolean

The post's hidden state.

Returns​

boolean


isHighlighted()​

isHighlighted(): Promise<boolean>

Returns whether this post is in its subreddit's community highlights.

Returns​

Promise<boolean>

Example​

const post = await reddit.getPostById('t3_123');
const isHighlighted = await post.isHighlighted();

isIgnoringReports()​

isIgnoringReports(): boolean

The post's report-ignore state.

Returns​

boolean


isLocked()​

isLocked(): boolean

The post's locked state.

Returns​

boolean


isNsfw()​

isNsfw(): boolean

The post's NSFW state.

Returns​

boolean


isQuarantined()​

isQuarantined(): boolean

The post's quarantine state.

Returns​

boolean


isRemoved()​

isRemoved(): boolean

The post's removal state.

Returns​

boolean


isSpam()​

isSpam(): boolean

The post's spam state.

Returns​

boolean


isSpoiler()​

isSpoiler(): boolean

The post's spoiler state.

Returns​

boolean


isStickied()​

isStickied(): boolean

The post's stickied state.

Returns​

boolean


lock()​

lock(): Promise<void>

Disables new comments and updates this instance's locked state.

Returns​

Promise<void>


markAsNsfw()​

markAsNsfw(): Promise<void>

Marks the post as NSFW and updates this instance.

Returns​

Promise<void>


markAsSpoiler()​

markAsSpoiler(): Promise<void>

Marks the post as a spoiler and updates this instance.

Returns​

Promise<void>


mergePostData()​

mergePostData(postData): Promise<void>

Shallow-merge postData with any existing post data.

Existing top-level properties are preserved unless the input replaces them. Nested objects are replaced rather than deeply merged.

Parameters​

postData​

JsonObject

Returns​

Promise<void>

Throws​

If the post data could not be updated.

Example​

const post = await reddit.getPostById(context.postId);

// Existing data:
// { currentScore: 55, settings: { theme: 'dark', fontSize: 12 } }

await post.mergePostData({ settings: { fontSize: 14 } });
// Result: { currentScore: 55, settings: { fontSize: 14 } }

remove()​

remove(isSpam?): Promise<void>

Removes the post and updates this instance's moderation state.

Parameters​

isSpam?​

boolean = false

Whether to classify the removed post as spam.

Returns​

Promise<void>


setCustomPostStyles()​

setCustomPostStyles(styles): Promise<void>

Experimental

Updates a custom post's styles.

Unspecified properties retain their existing values. Passing undefined removes all custom styles.

Parameters​

styles​

CustomPostStylesInput | undefined

Returns​

Promise<void>


setPostData()​

setPostData(postData): Promise<void>

Replace the post data stored on a custom post.

Parameters​

postData​

JsonObject

Represents the postData to be set, eg: { currentScore: 55, secretWord: 'barbeque' }

Returns​

Promise<void>

Throws​

Throws an error if the postData could not be set.

Example​

const post = await reddit.getPostById(context.postId);

// Existing postData: { settings: { theme: 'dark', fontSize: 12 } }

await post.setPostData({
currentScore: 55,
secretWord: 'barbeque',
});
// Result: { currentScore: 55, secretWord: 'barbeque' }

setSuggestedCommentSort()​

setSuggestedCommentSort(suggestedSort): Promise<void>

Sets the suggested default sort for the post's comments.

Parameters​

suggestedSort​

PostSuggestedCommentSort

Returns​

Promise<void>

Throws​

If the suggested sort is rejected.

Example​

const post = await reddit.getPostById(context.postId);
await post.setSuggestedCommentSort('NEW');

setTextFallback()​

setTextFallback(opts): Promise<void>

Replaces the content shown when a custom post cannot be rendered. Eg, on old.reddit.com.

The fallback may be plain text, Markdown, or rich text. This instance's body and edited state are updated from the response.

Parameters​

opts​

Readonly<SetCustomPostTextFallbackOptions>

Returns​

Promise<void>

Throws​

If the fallback could not be updated.

Example​

const newTextFallback = { text: 'This is an updated text fallback' };
const post = await context.reddit.getPostById(context.postId);
await post.setTextFallback(newTextFallback);

snoozeReports()​

snoozeReports(reason): Promise<void>

Snoozes subsequent reports with the same reason from the same users for seven days. This only works for free-form reports.

Parameters​

reason​

string

The report reason to snooze.

Returns​

Promise<void>


sticky()​

sticky(position?): Promise<void>

Pins the post in a sticky slot.

Parameters​

position?​

1 | 2 | 3 | 4

The sticky slot. If omitted, the bottom-most available slot is used. Use 1 or 2 for subreddit posts. 3 and 4 are reserved for profile pins.

Returns​

Promise<void>


toJSON()​

toJSON(): Pick<Post, "id" | "authorId" | "authorName" | "subredditId" | "subredditName" | "permalink" | "title" | "body" | "bodyHtml" | "url" | "thumbnail" | "score" | "numberOfComments" | "numberOfReports" | "createdAt" | "approved" | "spam" | "stickied" | "removed" | "removedBy" | "removedByCategory" | "archived" | "edited" | "locked" | "nsfw" | "quarantined" | "spoiler" | "hidden" | "ignoringReports" | "distinguishedBy" | "flair" | "authorFlair" | "secureMedia" | "userReportReasons" | "modReports" | "modReportReasons" | "crosspostParentId">

JSON representation of public fields.

Returns​

Pick<Post, "id" | "authorId" | "authorName" | "subredditId" | "subredditName" | "permalink" | "title" | "body" | "bodyHtml" | "url" | "thumbnail" | "score" | "numberOfComments" | "numberOfReports" | "createdAt" | "approved" | "spam" | "stickied" | "removed" | "removedBy" | "removedByCategory" | "archived" | "edited" | "locked" | "nsfw" | "quarantined" | "spoiler" | "hidden" | "ignoringReports" | "distinguishedBy" | "flair" | "authorFlair" | "secureMedia" | "userReportReasons" | "modReports" | "modReportReasons" | "crosspostParentId">


undistinguish()​

undistinguish(): Promise<void>

Removes the post's distinction and updates this instance.

Returns​

Promise<void>


unhide()​

unhide(): Promise<void>

Unhides the post for the app account and updates this instance.

Returns​

Promise<void>


unhighlight()​

unhighlight(): Promise<void>

Removes this post from its subreddit's community highlights. If this post is not highlighted, this is a no-op.

Returns​

Promise<void>


unignoreReports()​

unignoreReports(): Promise<void>

Stops ignoring reports and updates this instance's cached state.

Returns​

Promise<void>


unlock()​

unlock(): Promise<void>

Enables new comments and updates this instance's locked state.

Returns​

Promise<void>


unmarkAsNsfw()​

unmarkAsNsfw(): Promise<void>

Removes the NSFW designation and updates this instance.

Returns​

Promise<void>


unmarkAsSpoiler()​

unmarkAsSpoiler(): Promise<void>

Removes the spoiler designation and updates this instance.

Returns​

Promise<void>


unsnoozeReports()​

unsnoozeReports(reason): Promise<void>

Unsnoozes reports with the given reason. This only works for free-form reports.

Parameters​

reason​

string

The report reason to unsnooze.

Returns​

Promise<void>


unsticky()​

unsticky(): Promise<void>

Unpins the post without updating this instance's cached stickied value.

Returns​

Promise<void>


updateCrowdControlLevel()​

updateCrowdControlLevel(level): Promise<void>

Sets which comments Crowd Control collapses on this post.

Parameters​

level​

CrowdControlLevel

See CrowdControlLevel for the available levels.

Returns​

Promise<void>