跳到內容

Slash commands & application commands

本頁內容尚未翻譯。

Status Stable · Last verified 2026-07-11 · API v10 · Source Application commands

Application commands are the registered entry points users invoke. There are three kinds; “slash command” is the most common.

Type Value Trigger
CHAT_INPUT (slash) 1 Typing /name with options
USER 2 Right-click a user → Apps
MESSAGE 3 Right-click a message → Apps

USER and MESSAGE commands take no options — they act on the target user or message.

Options are the typed parameters of a CHAT_INPUT command. Verified option types:

Option type Value Notes
SUB_COMMAND 1 Groups options under a subcommand
SUB_COMMAND_GROUP 2 Groups subcommands (one level deep only)
STRING 3 Text; supports choices or autocomplete
INTEGER 4 Whole number; choices/autocomplete; min_value/max_value
BOOLEAN 5 true/false
USER 6 A user/member
CHANNEL 7 A channel (filter with channel_types)
ROLE 8 A role
MENTIONABLE 9 User or role
NUMBER 10 Floating point; choices/autocomplete; min/max
ATTACHMENT 11 An uploaded file
Limit Value
Command name length 1–32 characters
Command description length 1–100 characters
Options per command 25
Choices per option 25
Subcommand nesting one level deep (a group contains subcommands only)
Combined name + description + value size ≤ 8000 characters
Command creates 200 per day, per guild

CHAT_INPUT names must be lowercase and match Discord’s naming rules; enforce this before you register or the API rejects the command.

For long or dynamic value sets, use autocomplete instead of static choices:

  • Set autocomplete: true on a STRING, INTEGER, or NUMBER option. It cannot coexist with choices on the same option.
  • Discord sends an APPLICATION_COMMAND_AUTOCOMPLETE interaction (incoming type 4) as the user types; the currently-edited option is marked focused: true.
  • You respond with APPLICATION_COMMAND_AUTOCOMPLETE_RESULT (response type 8) containing up to 25 suggestions.
  • Suggestions are hints — the user is not limited to them, so re-validate the submitted value when the command actually runs.

Provide name_localizations and description_localizations — maps of locale → translated string, following the same naming rules. Localization is partial-friendly: supply only the locales you have, and Discord falls back to the default. This applies to commands, subcommands, options, and choice names.

Field Purpose
default_member_permissions A permission bitfield (string) gating who can use the command by default; server admins can override
contexts Where the command is usable: GUILD, BOT_DM, PRIVATE_CHANNEL
integration_types Install contexts it’s available in: GUILD_INSTALL (0), USER_INSTALL (1)
nsfw Marks an age-restricted command
dm_permission Deprecated — use contexts instead

integration_types + contexts are how a user-installed command follows the user across servers and DMs — see OAuth2 & installation.

Commands are managed via REST. Prefer PUT (bulk overwrite) — it’s idempotent and declares your whole command set at once:

Terminal window
# GLOBAL — all installs; takes time to propagate:
PUT https://discord.com/api/v10/applications/{application.id}/commands
# GUILD — one server; available immediately (great for development):
PUT https://discord.com/api/v10/applications/{application.id}/guilds/{guild.id}/commands
  • Guild commands are available in that guild immediately.
  • Global commands propagate across all guilds; expect a delay.

[!TIP] Observation Global propagation is commonly cited as “up to ~1 hour.” The current docs describe global commands as having “read-repair” and being available on all guilds, without pinning an exact time — so treat “up to an hour” as a rule of thumb, not a guarantee. Use guild registration while iterating.

Both example projects ship a register-commands.mjs that PUTs the set (honoring DISCORD_TEST_GUILD_ID for instant guild updates).