{"record":{"id":"8c42b87c77ab11d5","repo":"chenhg5/cc-connect","slug":"discord-send-image-w","errorCode":null,"errorMessage":"discord: send image: %w","messagePattern":"discord: send image: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/discord/discord.go","lineNumber":1086,"sourceCode":"\t\t\t\tFiles: []*discordgo.File{newFile()},\n\t\t\t})\n\t\t}\n\t\tif err != nil {\n\t\t\tslog.Warn(\"discord: interaction image failed, falling back to channel message\", \"error\", err)\n\t\t\t_, err = p.session.ChannelMessageSendComplex(rc.channelID, &discordgo.MessageSend{\n\t\t\t\tFiles: []*discordgo.File{newFile()},\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"discord: send image fallback: %w\", err)\n\t\t\t}\n\t\t}\n\t\treturn nil\n\tcase replyContext:\n\t\t_, err := p.session.ChannelMessageSendComplex(rc.targetChannelID(), &discordgo.MessageSend{\n\t\t\tFiles: []*discordgo.File{newFile()},\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"discord: send image: %w\", err)\n\t\t}\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"discord: SendImage: invalid reply context type %T\", rctx)\n\t}\n}\n\nfunc (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {\n\tname := file.FileName\n\tif name == \"\" {\n\t\tname = \"attachment\"\n\t}\n\n\tnewFile := func() *discordgo.File {\n\t\treturn &discordgo.File{\n\t\t\tName:        name,\n\t\t\tContentType: file.MimeType,\n\t\t\tReader:      bytes.NewReader(file.Data),","sourceCodeStart":1068,"sourceCodeEnd":1104,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/discord/discord.go#L1068-L1104","documentation":"SendImage failed while uploading an image to a regular channel via discordgo's ChannelMessageSendComplex with a Files attachment (the non-interaction branch of SendImage). The wrapped error is whatever Discord returned for the multipart upload — permissions, upload limits, invalid channel, or network failure.","triggerScenarios":"SendImage on a replyContext message where the bot lacks Attach Files or Send Messages permission; channel deleted/invalid ID; image data exceeding the guild upload cap; proxy/network failure during multipart upload.","commonSituations":"Server moderation removed the bot's Attach Files permission; large generated images (architecture diagrams, screenshots) hitting the 8 MiB default limit; wrong channel ID configured for the session.","solutions":["Read the wrapped discordgo error code: 403 → add Attach Files + Send Messages perms for the bot role; 404 → fix the channel ID","Compress or downscale images larger than the guild's upload limit before calling SendImage","Verify img.Data is a valid, non-empty image and MimeType is correct","Check proxy configuration and network reachability if the upload times out"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"const maxUpload = 8 << 20\nif len(img.Data) == 0 {\n    return fmt.Errorf(\"discord: empty image data\")\n}\nif len(img.Data) > maxUpload {\n    return fmt.Errorf(\"discord: image exceeds upload limit (%d bytes)\", len(img.Data))\n}","typeGuard":null,"tryCatchPattern":"var apiErr *discordgo.RESTError\nif errors.As(err, &apiErr) && apiErr.Message.Code == 50013 {\n    slog.Error(\"discord: bot lacks Attach Files permission\", \"channel\", rc.targetChannelID())\n}","preventionTips":["Pre-check image size against the guild upload cap","Grant the bot Attach Files + Send Messages permissions","Verify channel IDs resolve at session start","Validate MimeType against a small allowlist (png/jpeg/gif/webp)"],"tags":["discord","api-error","permissions","file-upload"],"backgroundTag":"http-error-response","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"}