chenhg5/cc-connect · error
discord: send image: %w
Error message
discord: send image: %w
What it means
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.
Source
Thrown at platform/discord/discord.go:1086
Files: []*discordgo.File{newFile()},
})
}
if err != nil {
slog.Warn("discord: interaction image failed, falling back to channel message", "error", err)
_, err = p.session.ChannelMessageSendComplex(rc.channelID, &discordgo.MessageSend{
Files: []*discordgo.File{newFile()},
})
if err != nil {
return fmt.Errorf("discord: send image fallback: %w", err)
}
}
return nil
case replyContext:
_, err := p.session.ChannelMessageSendComplex(rc.targetChannelID(), &discordgo.MessageSend{
Files: []*discordgo.File{newFile()},
})
if err != nil {
return fmt.Errorf("discord: send image: %w", err)
}
return nil
default:
return fmt.Errorf("discord: SendImage: invalid reply context type %T", rctx)
}
}
func (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {
name := file.FileName
if name == "" {
name = "attachment"
}
newFile := func() *discordgo.File {
return &discordgo.File{
Name: name,
ContentType: file.MimeType,
Reader: bytes.NewReader(file.Data),View on GitHub (pinned to 4000b2338a)
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
Defensive patterns
Strategy: fallback
Validate before calling
const maxUpload = 8 << 20
if len(img.Data) == 0 {
return fmt.Errorf("discord: empty image data")
}
if len(img.Data) > maxUpload {
return fmt.Errorf("discord: image exceeds upload limit (%d bytes)", len(img.Data))
} Try / catch
var apiErr *discordgo.RESTError
if errors.As(err, &apiErr) && apiErr.Message.Code == 50013 {
slog.Error("discord: bot lacks Attach Files permission", "channel", rc.targetChannelID())
} Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- discord: send image fallback: %w
- discord: send file fallback: %w
- discord: send fallback: %w
- discord: send: %w
- discord: send file: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/8c42b87c77ab11d5.
Report an issue: GitHub.