DIYgod/RSSHub · warning · InvalidParameterError
无法检测 Discuz 版本,请在路由中指定版本参数,如 /discuz/x/ 或 /discuz/7/
Error message
无法检测 Discuz 版本,请在路由中指定版本参数,如 /discuz/x/ 或 /discuz/7/
What it means
The Discuz route needs to know the forum software version (7.x or X/x) to apply the correct scraping selectors. It first checks the ver route parameter; if absent, it falls back to detecting the version from the HTML meta[name=generator] tag. If neither source yields a version string, InvalidParameterError instructs the user to specify the version explicitly in the route.
Source
Thrown at lib/routes/discuz/discuz.ts:125
const header = {
Cookie: cookie,
};
const { response, responseData } = await fetchWithAntiBot(link, header);
// 若没有指定编码,则默认utf-8
const contentType = response.headers['content-type'] || '';
let $ = load(iconv.decode(responseData, 'utf-8'));
const charset = contentType.match(/charset=([^;]*)/)?.[1] ?? $('meta[charset]').attr('charset') ?? $('meta[http-equiv="Content-Type"]').attr('content')?.split('charset=', 2)?.[1];
if (charset?.toLowerCase() !== 'utf-8') {
$ = load(iconv.decode(responseData, charset ?? 'utf-8'));
}
const version = ver ? `DISCUZ! ${ver}` : $('head > meta[name=generator]').attr('content');
if (!version) {
throw new InvalidParameterError('无法检测 Discuz 版本,请在路由中指定版本参数,如 /discuz/x/ 或 /discuz/7/');
}
let items;
if (version.toUpperCase().startsWith('DISCUZ! 7')) {
// discuz 7.x 系列
// 支持全文抓取,限制抓取页面5个
const list = $('tbody[id^="normalthread"] > tr')
.slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 5)
.toArray()
.map((item): DataItem => {
const $item = $(item);
const a = $item.find('span[id^=thread] a');
return {
title: a.text().trim(),
link: fixUrl(a.attr('href'), link),
pubDate: $item.find('td.author em').length ? parseDate($item.find('td.author em').text().trim()) : undefined,
author: $item.find('td.author cite a').text().trim(),
};View on GitHub (pinned to bed535e087)
Solutions
- Specify the version explicitly in the route path: use /discuz/x/<link> for Discuz X or /discuz/7/<link> for Discuz 7.x.
- Check the forum's HTML source in a browser to find the generator meta tag or identify the version from page elements.
- Verify the link parameter actually points to a Discuz forum (check for Discuz-specific CSS classes or scripts).
- If the forum uses a newer or custom Discuz version, check which scraping selectors work and specify the closest version.
Example fix
// Route usage — specify version explicitly // before: /discuz/https://example.com/forum.php // after: /discuz/x/https://example.com/forum.php
Defensive patterns
Strategy: validation
Validate before calling
const ver = ctx.req.param('ver')?.toUpperCase();
const version = ver ? `DISCUZ! ${ver}` : $('head > meta[name=generator]').attr('content');
if (!version) {
throw new InvalidParameterError('Cannot detect Discuz version. Specify it in the route: /discuz/x/<link> for X or /discuz/7/<link> for 7.x');
}
// Also validate the version is supported
if (!version.toUpperCase().startsWith('DISCUZ! 7') && !version.toUpperCase().startsWith('DISCUZ! X')) {
throw new InvalidParameterError(`Unsupported Discuz version: ${version}. Use /discuz/x/ or /discuz/7/`);
} Type guard
function isSupportedDiscuzVersion(version: string | undefined): boolean {
if (!version) return false;
const v = version.toUpperCase();
return v.startsWith('DISCUZ! 7') || v.startsWith('DISCUZ! X');
} Prevention
- Always specify the version parameter in the route URL (e.g., /discuz/x/) to avoid relying on auto-detection.
- Verify the URL points to an actual Discuz forum before using this route.
- Check the forum's HTML source for the meta[name=generator] tag to determine the version.
- Keep the route's version-specific selectors updated as Discuz releases new versions.
When it happens
Trigger: The ver parameter is not provided (undefined), and $('head > meta[name=generator]').attr('content') returns undefined — the forum's HTML does not include a generator meta tag. This happens with customized or stripped-down Discuz installations that remove the generator meta tag, or when the page returned is not actually a Discuz forum.
Common situations: A Discuz forum has been customized to remove the meta[name=generator] tag for security/fingerprinting reasons; the link parameter points to a non-Discuz page (e.g., a portal, WordPress, or error page); the forum uses a heavily modified template; the URL is correct but the initial page is a redirect.
Related errors
- 不支持当前Discuz版本.
- Invalid category
- At least one valid search parameter is required
- 通知类型${typeParam}未定义
- Unsupported language: ${language}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/e8e37fa59a60f378.
Report an issue: GitHub.