{"record":{"id":"6d29d756c0bc35c6","repo":"chenhg5/cc-connect","slug":"discord-send-preview-w","errorCode":null,"errorMessage":"discord: send preview: %w","messagePattern":"discord: send preview: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/discord/discord.go","lineNumber":1270,"sourceCode":"\tmessageID string\n}\n\n// SendPreviewStart sends a new message and returns a handle for subsequent edits.\nfunc (p *Platform) SendPreviewStart(ctx context.Context, rctx any, content string) (any, error) {\n\tvar channelID string\n\tswitch rc := rctx.(type) {\n\tcase replyContext:\n\t\tchannelID = rc.targetChannelID()\n\tcase *interactionReplyCtx:\n\t\tchannelID = rc.channelID\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"discord: invalid reply context type %T\", rctx)\n\t}\n\n\tmsg := buildDiscordPreviewMessage(content)\n\tsent, err := p.session.ChannelMessageSendComplex(channelID, msg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"discord: send preview: %w\", err)\n\t}\n\treturn &discordPreviewHandle{channelID: channelID, messageID: sent.ID}, nil\n}\n\n// UpdateMessage edits an existing message identified by previewHandle.\nfunc (p *Platform) UpdateMessage(ctx context.Context, previewHandle any, content string) error {\n\th, ok := previewHandle.(*discordPreviewHandle)\n\tif !ok {\n\t\treturn fmt.Errorf(\"discord: invalid preview handle type %T\", previewHandle)\n\t}\n\t_, err := p.session.ChannelMessageEditComplex(buildDiscordPreviewEdit(h.channelID, h.messageID, content))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"discord: edit message: %w\", err)\n\t}\n\treturn nil\n}\n\n// DeletePreviewMessage removes the preview message so the final response can","sourceCodeStart":1252,"sourceCodeEnd":1288,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/discord/discord.go#L1252-L1288","documentation":"After resolving a valid channel, SendPreviewStart sends the preview message with ChannelMessageSendComplex; failure there is wrapped as this error. It means the Discord API refused or failed the preview message send. The underlying discordgo error identifies the concrete cause.","triggerScenarios":"The target channel no longer exists or the bot lacks SEND_MESSAGES/VIEW_CHANNEL; the message payload is rejected (e.g. empty or too long content); network/API failure or 429 rate limit during preview streaming start.","commonSituations":"Thread archived or deleted between session creation and preview; permissions tightened mid-session; very long agent output triggering payload limits; Discord API outage.","solutions":["Inspect the wrapped Discord error code and fix the root cause (permissions, channel existence, payload)","Validate that the channel/thread is active before starting a preview stream","Truncate/limit preview content to Discord's message limits","Retry with backoff on 429/5xx errors"],"exampleFix":"// before\nsent, err := p.session.ChannelMessageSendComplex(chID, msg)\n// after\nsent, err := p.session.ChannelMessageSendComplex(chID, msg)\nif err != nil && isRetryable(err) { sent, err = retryWithBackoff(...) }","handlingStrategy":"retry","validationCode":"ch, err := p.session.Channel(channelID)\nif err != nil { return fmt.Errorf(\"target channel unavailable: %w\", err) }\nif ch.Type == discordgo.ChannelTypeGuildPublicThread && ch.ThreadMetadata.Archived {\n    return errors.New(\"thread archived; cannot send preview\")\n}","typeGuard":null,"tryCatchPattern":"handle, err := p.SendPreviewStart(ctx, rctx, content)\nif err != nil && isRetryable(err) {\n    time.Sleep(backoff)\n    handle, err = p.SendPreviewStart(ctx, rctx, content)\n}\nreturn handle, err","preventionTips":["Check channel/thread existence and archive state before streaming","Truncate preview content to Discord message limits","Back off on 429/5xx responses","Monitor bot permissions in target channels"],"tags":["discord","preview","channel-message","api-error"],"backgroundTag":"api-request-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}