chenhg5/cc-connect · error
discord: send file: %w
Error message
discord: send file: %w
What it means
This error wraps a failure from discordgo's ChannelMessageSendComplex when the platform tries to upload a file to a regular (non-interaction) Discord channel during SendFile. The library throws it whenever the Discord REST API rejects or fails the multipart file-upload request for a plain replyContext. It is a wrapper, so the root cause (permissions, size limits, network) is in the wrapped error.
Source
Thrown at platform/discord/discord.go:1142
Files: []*discordgo.File{newFile()},
})
}
if err != nil {
slog.Warn("discord: interaction file 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 file 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 file: %w", err)
}
return nil
default:
return fmt.Errorf("discord: SendFile: invalid reply context type %T", rctx)
}
}
func buildDiscordActionRows(rows [][]core.ButtonOption) []discordgo.MessageComponent {
components := make([]discordgo.MessageComponent, 0, len(rows))
for _, row := range rows {
if len(row) == 0 {
continue
}
buttons := make([]discordgo.MessageComponent, 0, len(row))
for idx, btn := range row {
style := discordgo.SecondaryButton
switch idx {
case 0:View on GitHub (pinned to 4000b2338a)
Solutions
- Inspect the wrapped error for the Discord API code (e.g. 50013 missing permissions, 40005 payload too large) and fix that cause
- Grant the bot ATTACH_FILES and VIEW_CHANNEL/SEND_MESSAGES permissions in the target channel
- Compress or split files so they fit under the guild's upload limit
- Verify the bot token is valid and the Discord gateway/API is reachable
- Retry on transient 5xx/network errors with backoff
Example fix
// before: failing on oversized file
err := p.SendFile(ctx, rctx, filePath)
// after: check size first
if fi.Size() > 25<<20 { return fmt.Errorf("file exceeds Discord upload limit") }
return p.SendFile(ctx, rctx, filePath) Defensive patterns
Strategy: try-catch
Validate before calling
if fi, err := os.Stat(filePath); err != nil || fi.Size() > 25<<20 {
return fmt.Errorf("file missing or too large for Discord: %v", err)
} Try / catch
if err := p.SendFile(ctx, rctx, path); err != nil {
var restErr *discordgo.RESTError
if errors.As(err, &restErr) {
log.Printf("discord file send failed: code=%d msg=%s", restErr.Message.Code, restErr.Message.Message)
}
return fmt.Errorf("send file: %w", err)
} Prevention
- Check bot ATTACH_FILES and SEND_MESSAGES permissions before sending
- Enforce a file-size cap below the guild upload limit (8MB default, 25MB boosted)
- Verify token validity at startup (cc-connect doctor style checks)
- Retry transient 5xx/429 errors with exponential backoff
When it happens
Trigger: Platform.SendFile is called with a replyContext and ChannelMessageSendComplex fails — e.g. the bot lacks ATTACH_FILES/SEND_MESSAGES permission in the channel, the file exceeds Discord's 8MB/25MB upload limit, or the HTTP request fails.
Common situations: Bot role missing attach-files permission after channel settings change; sending generated files larger than the guild's upload cap; expired/invalid bot token causing 401; transient Discord API 5xx or network outage.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- discord: send image fallback: %w
- discord: send image: %w
- discord: send file fallback: %w
- resolve channel %s: %w
- discord: create session: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/0c5b46029827fdea.
Report an issue: GitHub.