{"record":{"id":"bec031f00a5a9e39","repo":"babalae/better-genshin-impact","slug":"onebot-message-sending-failed","errorCode":null,"errorMessage":"OneBot message sending failed","messagePattern":"OneBot message sending failed","errorType":"exception","errorClass":"NotifierException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Notifier/OneBotNotifier.cs","lineNumber":83,"sourceCode":"                if (!privateResponse)\n                {\n                    success = false;\n                }\n            }\n\n            // 处理群聊消息\n            if (!string.IsNullOrEmpty(GroupId))\n            {\n                var groupResponse = await SendMessage(url, content, false);\n                if (!groupResponse)\n                {\n                    success = false;\n                }\n            }\n\n            if (!success)\n            {\n                throw new NotifierException(\"OneBot message sending failed\");\n            }\n        }\n        catch (NotifierException)\n        {\n            throw;\n        }\n        catch (System.Exception ex)\n        {\n            throw new NotifierException($\"Error sending OneBot message: {ex.Message}\");\n        }\n    }\n\n    private async Task<bool> SendMessage(string url, BaseNotificationData content, bool isPrivate)\n    {\n        // 构建消息内容\n        var messageContent = new List<object>\n        {\n            new","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Notifier/OneBotNotifier.cs#L65-L101","documentation":"Aggregated failure: SendMessage(url, content, isPrivate) returned false for every target that was attempted (private, group, or both). SendMessage returns false on non-success HTTP status OR when the JSON response's status field is not \"ok\".","triggerScenarios":"OneBot API returns non-2xx (wrong token, endpoint not /send_msg, framework down); OR returns 200 with status != \"ok\" (e.g. {\"status\":\"failed\",\"retcode\":1400,\"wording\":\"message not sent\"}); recipient QQ/group does not exist or bot is blocked; bot account not logged in.","commonSituations":"Access token mismatch (401/403); the OneBot instance is running but the QQ account got kicked offline; target user blocked the bot; group_id wrong; send_msg disabled by admin.","solutions":["Inspect the OneBot instance's own log for the retcode/wording (the notifier discards the body, losing detail).","Verify the access token matches the OneBot access_token setting.","Confirm the QQ account backing OneBot is online and that the bot can message the target (test manually via the OneBot HTTP API).","Improve SendMessage to read retcode/wording and bubble them into the exception."],"exampleFix":"// before\nusing var response = await _httpClient.SendAsync(request);\nif (!response.IsSuccessStatusCode)\n{\n    return false;\n}\nvar responseContent = await response.Content.ReadAsStringAsync();\n...\nreturn statusElement.GetString() == \"ok\";\n\n// after — surface the real reason\nusing var response = await _httpClient.SendAsync(request);\nvar responseContent = await response.Content.ReadAsStringAsync();\nif (!response.IsSuccessStatusCode)\n    throw new NotifierException($\"OneBot HTTP {response.StatusCode}: {responseContent}\");\nusing JsonDocument doc = JsonDocument.Parse(responseContent);\nvar root = doc.RootElement;\nvar status = root.TryGetProperty(\"status\", out var s) ? s.GetString() : null;\nif (status != \"ok\")\n    throw new NotifierException($\"OneBot status={status}, retcode={root.GetPropertyOrDefault(\"retcode\")}, msg={root.GetPropertyOrDefault(\"wording\")}\");\nreturn true;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await oneBotNotifier.SendAsync(data); }\ncatch (NotifierException ex) when (ex.Message == \"OneBot message sending failed\")\n{ /* inspect OneBot framework logs for retcode/wording; check token + recipient + bot online state */ }","preventionTips":["Improve SendMessage to surface retcode/wording in the exception.","Verify the access token and that the QQ account backing OneBot is online.","Confirm the bot can message the target (not blocked, group member)."],"tags":["onebot","api-failure","notifier","observability"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}