babalae/better-genshin-impact · warning · NotifierException
ServerChan SendKey为空
Error message
ServerChan SendKey为空
What it means
ServerChanNotifier.SendAsync rejects an empty _sendKey (passed to the constructor) before building the API URL, because the send key is the path credential for both sctapi.ftqq.com and the ft07.com push endpoints.
Source
Thrown at BetterGenshinImpact/Service/Notifier/ServerChanNotifier.cs:33
public class ServerChanNotifier : INotifier
{
public string Name { get; set; } = "ServerChan";
private readonly HttpClient _httpClient;
private readonly string _sendKey;
public ServerChanNotifier(HttpClient httpClient, string sendKey)
{
_httpClient = httpClient;
_sendKey = sendKey;
}
public async Task SendAsync(BaseNotificationData content)
{
if (string.IsNullOrEmpty(_sendKey))
{
throw new NotifierException("ServerChan SendKey为空");
}
try
{
// 获取正确的API URL
string apiUrl = GetServerChanApiUrl(_sendKey);
// 生成通知标题和内容
string title = $"BetterGI·更好的原神";
string desp = GenerateDescription(content);
// 准备表单数据
var postData = $"title={Uri.EscapeDataString(title)}&desp={Uri.EscapeDataString(desp)}";
// 创建请求
var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
request.Content = new StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded");
View on GitHub (pinned to a7cb36712d)
Solutions
- Obtain a SendKey from ServerChan (sct.ftqq.com) or ServerChanTurbo (ft07.com) and save it in settings.
- Gate notifier construction/registration on a non-empty key.
- Add settings UI validation that blocks enabling the channel without a key.
Example fix
// before
var n = new ServerChanNotifier(httpClient, sendKey);
// after
if (string.IsNullOrWhiteSpace(sendKey))
throw new InvalidOperationException("ServerChan SendKey must be configured before constructing the notifier.");
var n = new ServerChanNotifier(httpClient, sendKey); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(sendKey))
throw new InvalidOperationException("Configure a ServerChan SendKey before sending."); Type guard
static bool IsServerChanConfigured(string sendKey) => !string.IsNullOrWhiteSpace(sendKey);
Try / catch
try { await serverChanNotifier.SendAsync(data); }
catch (NotifierException ex) when (ex.Message.Contains("SendKey为空"))
{ /* prompt user to paste SendKey, no retry */ } Prevention
- Block enabling ServerChan until a SendKey is entered.
- Trim whitespace from the key on save.
When it happens
Trigger: ServerChanNotifier constructed with sendKey="" or null; the line-31 IsNullOrEmpty(_sendKey) guard fires.
Common situations: User enabled ServerChan but never pasted a SendKey; key cleared during settings reset; SCT vs SCTP2024 migration removed the old key.
Related errors
- Invalid key format for sctp.
- MeoW 昵称为空
- OneBot endpoint is not set
- OneBot requires either a user ID or group ID
- Invalid Telegram proxy URL format: {proxyUrl}. Details: {ex.
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/cd220f15f239ecbd.
Report an issue: GitHub.