{"record":{"id":"3f61494e183e1893","repo":"chenhg5/cc-connect","slug":"discord-edit-message-w","errorCode":null,"errorMessage":"discord: edit message: %w","messagePattern":"discord: edit message: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/discord/discord.go","lineNumber":1283,"sourceCode":"\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\n// be sent as a fresh message (avoids notification confusion).\nfunc (p *Platform) DeletePreviewMessage(ctx context.Context, previewHandle any) error {\n\th, ok := previewHandle.(*discordPreviewHandle)\n\tif !ok {\n\t\treturn fmt.Errorf(\"discord: invalid preview handle type %T\", previewHandle)\n\t}\n\treturn p.session.ChannelMessageDelete(h.channelID, h.messageID)\n}\n\n// StartTyping sends a typing indicator and repeats every 8 seconds\n// (Discord typing status lasts ~10s) until the returned stop function is called.\nfunc (p *Platform) StartTyping(ctx context.Context, rctx any) (stop func()) {\n\trc, ok := rctx.(replyContext)","sourceCodeStart":1265,"sourceCodeEnd":1301,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/discord/discord.go#L1265-L1301","documentation":"discord: edit message wraps an error returned by discordgo's ChannelMessageEditComplex when updating a previously sent streaming preview message fails. The platform uses this call to update the preview card in place as the agent streams output. Any Discord API failure (network, auth, deleted message, rate limit) surfaces wrapped here.","triggerScenarios":"Calling UpdateMessage (message edit path, discord.go:1283) with a *discordPreviewHandle whose messageID was deleted, channel perms revoked, token expired, or Discord returning 4xx/5xx/network error.","commonSituations":"User (or bot cleanup) deleted the preview message mid-stream; bot lost 'Send Messages'/'Manage Messages' permission; invalid or expired bot token; Discord 429 rate limiting during heavy streaming edits.","solutions":["Check bot permissions in the guild (Manage Messages / Send Messages in that channel)","Verify the messageID still exists (not deleted) before editing; fall back to sending a new message on error","Validate DISCORD bot token and network connectivity","Add retry with backoff for 429/5xx responses"],"exampleFix":"// before\n_, err := p.session.ChannelMessageEditComplex(buildDiscordPreviewEdit(h.channelID, h.messageID, content))\nif err != nil { return fmt.Errorf(\"discord: edit message: %w\", err) }\n// after\n_, err := p.session.ChannelMessageEditComplex(buildDiscordPreviewEdit(h.channelID, h.messageID, content))\nif err != nil {\n    if strings.Contains(err.Error(), \"404\") {\n        return p.sendNewMessage(h.channelID, content) // message was deleted; send fresh\n    }\n    return fmt.Errorf(\"discord: edit message: %w\", err)\n}","handlingStrategy":"retry","validationCode":"if handle == nil || handle.messageID == \"\" { return errors.New(\"no preview message to edit\") }","typeGuard":"h, ok := previewHandle.(*discordPreviewHandle); if !ok || h == nil { /* skip edit */ }","tryCatchPattern":"_, err := p.session.ChannelMessageEditComplex(edit)\nif err != nil {\n    if isRateLimit(err) { backoffAndRetry() } else { logAndFallbackToSend() }\n}","preventionTips":["Check bot channel permissions at startup (doctor command)","Cache message existence; fall back to fresh send on 404","Apply client-side rate limiting for streaming edits"],"tags":["discord","api-edit","network"],"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-14T00:17:10.932Z"}