babalae/better-genshin-impact · warning · NotifierException

OneBot requires either a user ID or group ID

Error message

OneBot requires either a user ID or group ID

What it means

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.

Source

Thrown at BetterGenshinImpact/Service/Notifier/OneBotNotifier.cs:47

    public OneBotNotifier(HttpClient httpClient, string endpoint = "", string userId = "", string groupId = "", string token = "")
    {
        _httpClient = httpClient;
        Endpoint = endpoint;
        UserId = userId;
        GroupId = groupId;
        Token = token;
    }

    public async Task SendAsync(BaseNotificationData content)
    {
        if (string.IsNullOrEmpty(Endpoint))
        {
            throw new NotifierException("OneBot endpoint is not set");
        }
        
        if (string.IsNullOrEmpty(UserId) && string.IsNullOrEmpty(GroupId))
        {
            throw new NotifierException("OneBot requires either a user ID or group ID");
        }

        try
        {
            // 确保URL以/send_msg结尾
            var url = Endpoint.TrimEnd('/');
            if (!url.EndsWith("/send_msg"))
            {
                url += "/send_msg";
            }

            bool success = true;

            // 处理私聊消息
            if (!string.IsNullOrEmpty(UserId))
            {
                var privateResponse = await SendMessage(url, content, true);
                if (!privateResponse)

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Provide either a QQ user ID (for private message) or a group ID (for group message) in settings.
  2. Validate at settings-save time that at least one recipient is set when the channel is enabled.

Example fix

// before
if (string.IsNullOrEmpty(UserId) && string.IsNullOrEmpty(GroupId))
{
    throw new NotifierException("OneBot requires either a user ID or group ID");
}

// after — also guard in the settings VM before enabling the channel
if (string.IsNullOrEmpty(UserId) && string.IsNullOrEmpty(GroupId))
{
    throw new NotifierException("OneBot requires either a user ID or group ID");
}
// settings VM:
// if (enabled && string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(groupId))
//     ThemedMessageBox.Show("请至少填写 QQ 号或群号");
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(groupId))
    throw new InvalidOperationException("Provide a QQ user id or group id for OneBot.");

Type guard

static bool HasOneBotRecipient(string userId, string groupId)
    => !string.IsNullOrEmpty(userId) || !string.IsNullOrEmpty(groupId);

Try / catch

try { await oneBotNotifier.SendAsync(data); }
catch (NotifierException ex) when (ex.Message.Contains("user ID or group ID"))
{ /* prompt user, no retry */ }

Prevention

When it happens

Trigger: Both UserId and GroupId passed to the constructor are null/empty; the line-45 IsNullOrEmpty && IsNullOrEmpty guard fires.

Common situations: User set up the OneBot channel and endpoint but left both recipient fields blank; only the token was configured.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/0a13dba08a666089. Report an issue: GitHub.