{"record":{"id":"305e55d54c667093","repo":"chenhg5/cc-connect","slug":"discord-send-w","errorCode":null,"errorMessage":"discord: send: %w","messagePattern":"discord: send: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/discord/discord.go","lineNumber":1019,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"discord: send fallback: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (p *Platform) sendChannelReply(rc replyContext, content string) error {\n\tchunks := core.SplitMessageCodeFenceAware(wrapTablesInCodeBlocks(content), maxDiscordLen)\n\tfor _, chunk := range chunks {\n\t\tvar err error\n\t\tif rc.useThreadChannel() || rc.messageID == \"\" {\n\t\t\t_, err = p.session.ChannelMessageSend(rc.targetChannelID(), chunk)\n\t\t} else {\n\t\t\tref := &discordgo.MessageReference{MessageID: rc.messageID}\n\t\t\t_, err = p.session.ChannelMessageSendReply(rc.channelID, chunk, ref)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"discord: send: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (p *Platform) sendChannel(rc replyContext, content string) error {\n\tchunks := core.SplitMessageCodeFenceAware(wrapTablesInCodeBlocks(content), maxDiscordLen)\n\tfor _, chunk := range chunks {\n\t\t_, err := p.session.ChannelMessageSend(rc.targetChannelID(), chunk)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"discord: send: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// SendImage sends an image to the channel or interaction.\n// Implements core.ImageSender.","sourceCodeStart":1001,"sourceCodeEnd":1037,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/discord/discord.go#L1001-L1037","documentation":"sendChannelReply failed on the discordgo message-send call. It either uses ChannelMessageSendReply (with a MessageReference to reply inline) or falls back to ChannelMessageSend when replying in a thread or when no message ID is available. Any Discord API rejection of the send — most commonly 403 Missing Permissions, 404 Unknown Channel/Message, or a network failure — is wrapped here.","triggerScenarios":"Reply() on a normal channel message where the bot lacks Send Messages permission; the referenced messageID was deleted (404 Unknown Message on the reply endpoint); the channel is read-only or the bot was kicked from the guild; transient network/proxy failure to discord.com.","commonSituations":"Bot missing role permissions in a restricted channel; user deleted their message before the agent reply arrived; message content intent/permission changes after a server reshuffle; Discord rate limits (429) under heavy reply traffic.","solutions":["Read the wrapped discordgo error code: 403 → add Send Messages/View Channel/Read Message History perms for the bot role; 404 → the channel or referenced message no longer exists","Grant the bot the required permissions or move the bot to a role with channel access","If the referenced message may vanish, clear messageID so sendChannelReply uses the plain ChannelMessageSend path","Check for 429 rate-limit errors and add backoff/retry around replies"],"exampleFix":"// before\n_, err = p.session.ChannelMessageSendReply(rc.channelID, chunk, ref)\n// after\n_, err = p.session.ChannelMessageSendReply(rc.channelID, chunk, ref)\nif isUnknownMessage(err) {\n    _, err = p.session.ChannelMessageSend(rc.targetChannelID(), chunk)\n}","handlingStrategy":"retry","validationCode":"perms, _ := p.session.State.UserChannelPermissions(p.botID, rc.channelID)\nif perms&discordgo.PermissionSendMessages == 0 {\n    return fmt.Errorf(\"bot cannot send in channel %s\", rc.channelID)\n}","typeGuard":null,"tryCatchPattern":"var apiErr *discordgo.RESTError\nif errors.As(err, &apiErr) && apiErr.Message.Code == 10008 {\n    // Unknown Message: referenced message was deleted — resend without reference\n    _, err = p.session.ChannelMessageSend(rc.targetChannelID(), chunk)\n}","preventionTips":["Ensure the bot role has Send Messages, View Channel, and Read Message History","Handle deleted referenced messages by falling back to non-reply send","Add backoff on 429 rate-limit responses","Verify channel IDs in config exist and the bot is in that guild"],"tags":["discord","api-error","permissions"],"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-14T00:17:10.932Z"}