devvit icon indicating copy to clipboard operation
devvit copied to clipboard

Unable to comment richtext only

Open tip2663 opened this issue 7 months ago • 1 comments

Hey, I am trying to comment like so:

const reply = await context.reddit.submitComment({
        id: targetId,
        richtext: new RichTextBuilder().animatedImage({mediaId:response.mediaId}),
        runAs:"USER"
      })

But this gives me the following error:

Error: 2 UNKNOWN: Errors:
NO_TEXT: we need something here: text
    at callErrorFromStatus (/srv/index.cjs:5299:21)
    at Object.onReceiveStatus (/srv/index.cjs:5980:70)
    at Object.onReceiveStatus (/srv/index.cjs:5782:140)
    at Object.onReceiveStatus (/srv/index.cjs:5748:178)
    at /srv/index.cjs:15443:77
    at process.processTicksAndRejections (node:internal/process/task_queues:85:11)
for call at
    at Client2.makeUnaryRequest (/srv/index.cjs:5950:32)
    at /srv/index.cjs:139738:62
    at /srv/index.cjs:139797:5
    at new Promise (<anonymous>)
    at GrpcWrapper._GrpcWrapper_promiseWithGrpcCallback2 (/srv/index.cjs:139795:10)
    at GrpcWrapper.request (/srv/index.cjs:139737:110)
    at GenericPluginClient.Comment (/srv/index.cjs:124879:93)
    at wrapped.<computed> [as Comment] (main.js:36536:141)
    at Comment.submit (main.js:39713:35)
    at RedditAPIClient.submitComment (main.js:29735:20) {
  code: 2,
  details: 'Errors:\nNO_TEXT: we need something here: text',
  metadata: _Metadata { internalRepr: Map(0) {}, options: {} }

The docs say either text or richtext should be there:

(method) RedditAPIClient.submitComment(options: CommentSubmissionOptions & {
    id: string;
}): Promise<Comment>
Submit a new comment to a post or comment.

@param options — You must provide either options.text or options.richtext but not both.

@param options.id — The ID of the post or comment to comment on. e.g. 't3_1qjpg' for post and 't1_1qgif' for comment

@param options.text — The text of the comment

@param options.richtext — The rich text of the comment

@param options.runAs — The user type to submit the comment as, eg 'APP' or 'USER'

@returns — A Promise that resolves to a Comment object.

@example

import { RunAs } from '@devvit/public-api';

So I believe this to be a bug!

tip2663 avatar May 14 '25 12:05 tip2663

thanks for the report, @tip2663! I haven't been able to repro this issue. can you please give it another try on the latest version of Devvit? here's the code I tried:

const upload = await media.upload({
  type: 'image',
  url: 'https://styles.redditmedia.com/t5_e5k98u/styles/communityIcon_30h25pf0lplf1.png?width=64&height=64&frame=1&auto=webp&crop=64:64,smart&s=00425316d32febb23d8e28775d9b62310da40bdc'
})

console.log('uploaded')

const richtext = new RichTextBuilder().image({
  mediaId: upload.mediaId
})
const comment = await reddit.submitComment({
  richtext,
  id: context.postId
})
console.log('commented', comment.id)

niedzielski avatar Nov 25 '25 18:11 niedzielski