Skip to content

slash command name regex within documentation is incorrect #7712

@puppy0cam

Description

@puppy0cam

Description

The regex for validating command names appears to be outdated or incorrect
I'm trying to add localisation for my bot commands, but when I try to wipe out the invalid command names with the regex provided by the docs, I still get errors.
{"message": "Invalid Form Body", "code": 50035, "errors": {"0": {"name_localizations": {"_errors": [{"code": "APPLICATION_COMMAND_INVALID_NAME", "message": "Command name is invalid"}]}}}}

for (const i of commands) {
  if (i.type === 1 && i.name_localizations) {
    for (const key of Object.keys(i.name_localizations)) {
      if (!key.match(/^[-_'\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u)) {
        delete i.name_localizations[key];
      }
    }
  }
}

Not to mention that the error itself doesn't quite make sense. Why isn't it pointing out the specific locale that it takes issue with? Shouldn't it be giving an error for each of the problematic locales on this list like it does for localisations of option names?

Steps to Reproduce

Attempt to register the following command:

[
        {
                "type": 1,
                "name": "setup",
                "name_localizations": {
                        "id": "pengaturan",
                        "en-US": "setup",
                        "en-GB": "set-up",
                        "bg": "настройка",
                        "zh-CN": "设置",
                        "zh-TW": "設定",
                        "hr": "postavljanje",
                        "cs": "nastavit",
                        "da": "opsætning",
                        "nl": "instellen",
                        "fi": "asennus",
                        "fr": "configuration",
                        "de": "Einrichtung",
                        "el": "ρύθμιση",
                        "hi": "सेटअप",
                        "hu": "beállítás",
                        "it": "configurazione",
                        "ja": "セットアップ",
                        "ko": "설정",
                        "lt": "nustatyti",
                        "no": "oppsett",
                        "pl": "konfiguracja",
                        "pt-BR": "configuração",
                        "ro": "configurați",
                        "ru": "настройка",
                        "es-ES": "configuración",
                        "es-419": "configuración",
                        "sv-SE": "installera",
                        "th": "การตั้งค่า",
                        "tr": "kurulum",
                        "uk": "налаштування"
                },
                "description": "Setup the bot"
        }
]

Expected Behavior

The regex displayed in the documentation can be used to filter out invalid translations.
In addition, the API properly reports which localisation of the name is causing problems instead of the entire name_localizations object

Current Behavior

The regex displayed in the documentation does not cover all invalid characters
The API does not indicate which localised name is the cause of the problem.

Screenshots/Videos

No response

Client and System Information

stable 422534 (f2291ea) Host 1.0.9200 x64 (66535) Build Override: N/A Windows 10 64-bit (10.0.19045)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions