Skip to content

feat: register Discord command groups - #9445

Draft
casama233 wants to merge 1 commit into
AstrBotDevs:masterfrom
casama233:feat/discord-command-groups
Draft

feat: register Discord command groups#9445
casama233 wants to merge 1 commit into
AstrBotDevs:masterfrom
casama233:feat/discord-command-groups

Conversation

@casama233

@casama233 casama233 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Relates to #9258.

Note

This is a Draft proposal for maintainer feedback. It does not migrate any plugin commands by itself and is not requesting immediate merge.

Discord currently skips CommandGroupFilter and every child CommandFilter during application command registration. Plugins that use AstrBot command groups therefore have no discoverable Discord slash command, while plugins that flatten their command tree can consume a large part of Discord's application command quota.

The proposed mapping was discussed in #9258 before implementation:
#9258 (comment)

A separate Draft plugin migration demonstrates the intended consumer without coupling its review or merge to this core PR:
vmoranv-reborn/astrbot_plugin_pixiv_reborn#48

Modifications / 改动点

  • Register each root CommandGroupFilter as one Pycord SlashCommandGroup.
  • Register direct child commands as Discord subcommands.
  • Register one nested AstrBot group level as a Discord subcommand group.
  • Rebuild the complete AstrBot command path in leaf callbacks, so the existing waking and filter pipeline remains unchanged.
  • Keep the current optional params string on each leaf command. This avoids overlapping with the separate typed-option work in Discord 适配器增强功能 #9125.
  • Skip deeper nesting with an explicit warning because Discord only supports command -> subcommand group -> subcommand.
  • Enforce Discord's 25-option limit, name validation, duplicate handling, disabled-command filtering, and 100-character descriptions.
  • Ignore nested group metadata during the outer registry scan, ensuring the complete tree consumes only one top-level Discord command.
  • Add tests for registration count and shape, full callback paths, and unsupported deep nesting.

Scope boundary:

  • Existing flattened plugin commands are not rewritten or removed.

  • Plugins opt in only by using AstrBot's existing command_group decorators.

  • This PR is independent of the Pixiv authentication PR and can be reviewed on its own.

  • No new dependency is introduced.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Verification steps:

make pr-test-neo

Result:

Ruff format check: passed
Ruff lint check: passed
Pytest: 12 passed
Startup smoke test on http://localhost:6185: passed
PR checks completed successfully

GitHub Actions also pass across the repository test suite, build, format check,
CodeQL, and startup smoke tests on Ubuntu, macOS, and Windows with Python
3.10–3.14.

The generated payload was also checked with the real Pycord classes. A root group with one direct command and one nested group serializes as:

/pixiv
├── search
└── user
    └── detail

The two leaf callbacks rebuild pixiv search <params> and pixiv user detail <params> respectively.


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Register Discord slash commands for AstrBot command groups so grouped commands appear as a single top-level slash command with subcommands and one level of subcommand groups.

New Features:

  • Expose root AstrBot command groups as Discord SlashCommandGroup entries with direct commands and one nested group level mapped to subcommands and subcommand groups.
  • Preserve full AstrBot command paths in Discord leaf callbacks while keeping the existing free-form params string for command arguments.

Enhancements:

  • Centralize Discord slash command name validation and description normalization, enforcing Discord limits on names, descriptions, and option counts.
  • Ensure grouped commands share a single top-level Discord command to reduce global command usage and skip unsupported deep nesting with explicit warnings.

Tests:

  • Add tests covering registration of command groups as a single slash command tree, reconstruction of full command paths in callbacks, and warnings for command groups nested deeper than one level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant