{"record":{"id":"0a13dba08a666089","repo":"babalae/better-genshin-impact","slug":"onebot-requires-either-a-user-id-or-group-id","errorCode":null,"errorMessage":"OneBot requires either a user ID or group ID","messagePattern":"OneBot requires either a user ID or group ID","errorType":"validation","errorClass":"NotifierException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Service/Notifier/OneBotNotifier.cs","lineNumber":47,"sourceCode":"    public OneBotNotifier(HttpClient httpClient, string endpoint = \"\", string userId = \"\", string groupId = \"\", string token = \"\")\n    {\n        _httpClient = httpClient;\n        Endpoint = endpoint;\n        UserId = userId;\n        GroupId = groupId;\n        Token = token;\n    }\n\n    public async Task SendAsync(BaseNotificationData content)\n    {\n        if (string.IsNullOrEmpty(Endpoint))\n        {\n            throw new NotifierException(\"OneBot endpoint is not set\");\n        }\n        \n        if (string.IsNullOrEmpty(UserId) && string.IsNullOrEmpty(GroupId))\n        {\n            throw new NotifierException(\"OneBot requires either a user ID or group ID\");\n        }\n\n        try\n        {\n            // 确保URL以/send_msg结尾\n            var url = Endpoint.TrimEnd('/');\n            if (!url.EndsWith(\"/send_msg\"))\n            {\n                url += \"/send_msg\";\n            }\n\n            bool success = true;\n\n            // 处理私聊消息\n            if (!string.IsNullOrEmpty(UserId))\n            {\n                var privateResponse = await SendMessage(url, content, true);\n                if (!privateResponse)","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Notifier/OneBotNotifier.cs#L29-L65","documentation":"OneBotNotifier requires at least one delivery target: a private-message user_id OR a group-message group_id. If both UserId and GroupId are empty, SendAsync refuses to send because SendMessage would have no recipient.","triggerScenarios":"Both UserId and GroupId passed to the constructor are null/empty; the line-45 IsNullOrEmpty && IsNullOrEmpty guard fires.","commonSituations":"User set up the OneBot channel and endpoint but left both recipient fields blank; only the token was configured.","solutions":["Provide either a QQ user ID (for private message) or a group ID (for group message) in settings.","Validate at settings-save time that at least one recipient is set when the channel is enabled."],"exampleFix":"// before\nif (string.IsNullOrEmpty(UserId) && string.IsNullOrEmpty(GroupId))\n{\n    throw new NotifierException(\"OneBot requires either a user ID or group ID\");\n}\n\n// after — also guard in the settings VM before enabling the channel\nif (string.IsNullOrEmpty(UserId) && string.IsNullOrEmpty(GroupId))\n{\n    throw new NotifierException(\"OneBot requires either a user ID or group ID\");\n}\n// settings VM:\n// if (enabled && string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(groupId))\n//     ThemedMessageBox.Show(\"请至少填写 QQ 号或群号\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(groupId))\n    throw new InvalidOperationException(\"Provide a QQ user id or group id for OneBot.\");","typeGuard":"static bool HasOneBotRecipient(string userId, string groupId)\n    => !string.IsNullOrEmpty(userId) || !string.IsNullOrEmpty(groupId);","tryCatchPattern":"try { await oneBotNotifier.SendAsync(data); }\ncatch (NotifierException ex) when (ex.Message.Contains(\"user ID or group ID\"))\n{ /* prompt user, no retry */ }","preventionTips":["Require at least one recipient before enabling the OneBot channel.","Test the recipient id by sending a manual message via the OneBot HTTP API."],"tags":["onebot","config","validation","notifier"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}