修复了DISCORD适配器注册命令正则过于严格的问题#9102
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider adding a brief inline comment explaining why the regex intentionally diverges from Discord’s official lowercase
a-z0-9_-naming rule to allow Unicode/Chinese, so future maintainers don’t “fix” it back. - Using
\wwithre.UNICODEwill allow a broad set of Unicode letters (e.g., Cyrillic, Greek) and digits; if the intent is specifically Chinese (or a limited set of locales), you may want to restrict the character classes more narrowly. - Double-check whether including the apostrophe
'in the allowed characters is intentional for Discord slash command names; if not, removing it from the regex will avoid accepting potentially invalid names.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding a brief inline comment explaining why the regex intentionally diverges from Discord’s official lowercase `a-z0-9_-` naming rule to allow Unicode/Chinese, so future maintainers don’t “fix” it back.
- Using `\w` with `re.UNICODE` will allow a broad set of Unicode letters (e.g., Cyrillic, Greek) and digits; if the intent is specifically Chinese (or a limited set of locales), you may want to restrict the character classes more narrowly.
- Double-check whether including the apostrophe `'` in the allowed characters is intentional for Discord slash command names; if not, removing it from the regex will avoid accepting potentially invalid names.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request updates the regular expression used to validate Discord slash command names to allow a broader set of characters. The reviewer noted that Discord slash commands do not allow uppercase letters, which the new \w pattern would match, potentially causing API errors. They suggested adding a lowercase check and removing the redundant re.UNICODE flag.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
# Discord 支持 Unicode 命令名(如中文),放宽匹配并确保全小写 Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
针对:[Bug]Discord适配器中,注册命令匹配正则 [a-z0-9_-] 应当改成 [\w-] #9101
修复了discord斜杠的中文命令无法注册的问题
我就改了一行代码
改前
if not re.match(r"^[a-z0-9_-]{1,32}$", cmd_name):
改后
if not re.match(r"^[-_'\w]{1,32}$", cmd_name, re.UNICODE):
再无任何破坏性改动和其他改动
Summary by Sourcery
Bug Fixes: