Command builders
guideBuilding slash, user and message commands as plain objects instead of structures, and mixing the two.
This page covers the builder path to an application command: plain objects you assemble in Skript, as an alternative to slash command and user command / message command. You're assumed to have a bot named "my-bot" logged in.
How builders work
A builder is a command object with settable properties: a name, a description, options, subcommands. It has no trigger and nothing reaches Discord until a script pushes it with update or register, the same effects a structure uses.
on guild ready: set {_roll} to a new slash command named "roll" with description "Roll a dice" set {_sides} to a new integer option named "sides" with description "How many sides" set min value of {_sides} to 2 set max value of {_sides} to 100 add {_sides} to options of {_roll} register the discord command {_roll} in event-guild
Unlike DiSky's entity builders elsewhere, there's no separate "build result": the effects above push the object itself, and command id of {_roll} is only set afterwards, once Discord answers.
[a] new slash command (named|with [the] name) %string% with [the] desc[ription] %string%Creates a slash command. The name must be lowercase, 1 to 32 characters, without spaces.Answering a built command
A builder-declared command has no trigger of its own, so it's answered in the generic on slash command, matched by name. Read an option with slash option "name"; an omitted optional option is not set.
on slash command: if used slash command is "roll": set {_sides} to slash option "sides" if {_sides} is not set: set {_sides} to 6 reply with hidden "You rolled %random integer between 1 and {_sides}%"
Properties
Every builder type shares the applicationcommand properties below; slashcommand and slashoption add their own on top.
Property | Default | Accepted values |
|---|---|---|
the name given at creation | text, following the same naming rules as the structure it mirrors | |
not set | read-only, set once the command is registered | |
fixed by how it was created |
|
enabled for, disabled, nsfw, contexts and integration types also apply to every builder; see Command settings.
Property (slashcommand) | Default | Accepted values |
|---|---|---|
the text given at creation | any text | |
empty | a list of | |
empty | a list of | |
empty | a list of |
Property (slashoption) | Default | Accepted values |
|---|---|---|
the text given at creation | any text | |
fixed by how it was created | read-only | |
|
| |
|
| |
none | up to 25 | |
none | a number; integer and number options only | |
none | a number; integer and number options only | |
none |
| |
none |
| |
empty (any channel) | a list of channel types; channel options only |
[a] new %optiontype% [slash] option (named|with [the] name) %string% with [the] desc[ription] %string%Creates an option of the given Discord type (string, integer, number, boolean, user, channel, role, mentionable, attachment). It is optional and without autocomplete until you say otherwise.Subcommands and groups
A subcommand is a /root sub entry with its own description and options; a subcommandgroup groups several subcommands under /root group sub. A slash command has either options or subcommands (with or without groups), never both.
on guild ready: set {_mod} to a new slash command named "mod" with description "Moderation tools" set {_ban} to a new subcommand named "ban" with description "Ban a member" add a new user option named "target" with description "Who to ban" to options of {_ban} add {_ban} to subcommands of {_mod} set {_kick} to a new subcommand named "kick" with description "Kick a member" add a new user option named "target" with description "Who to kick" to options of {_kick} add {_kick} to subcommands of {_mod} register the discord command {_mod} in event-guild
/mod ban and /mod kick above match the same structure-declared shape from Slash commands; a subcommand group adds one more level: build it with a new subcommand group named ... with description ..., add subcommands to it, then add the group to subcommand groups of the command.
[a] new sub[ ]command (named|with [the] name) %string% with [the] desc[ription] %string%Creates a subcommand. Same naming rules as a slash command.Mixing structures and builders
structured slash command "mod" reads a structure-declared command back as the same kind of object a builder makes: editable, and separate from the .sk file that declared it. Localize it, add an option, then push it like any other object.
on guild ready: set {_mod} to structured slash command "mod" localize the description of {_mod} in "fr" to "Outils de modération" register the discord command {_mod} in event-guild
A structure and a builder can also be pushed side by side, in one call: update the discord commands (all structured application commands) and {_roll} in event-guild replaces every structure-declared command and adds {_roll} in the same PUT. A structure-declared command still runs its own trigger; a builder-declared one only ever answers in the generic event. Both fire the generic event first, whichever way they were declared.
Errors you may see
Message (console) | Cause | Fix |
|---|---|---|
'sub_command' is not an option type; use a subcommand or a subcommand group instead (same wording for | a new option was built with a structural type instead of an actual | build a |
a <type> option cannot have autocomplete |
| only string, integer and number options support autocomplete |
only integer and number options have a minimum value (same wording for maximum) |
| only integer and number options accept bounds |
the choice 'x' has a text value but its option is an integer option (or a number option) | a | give the choice a numeric value, or switch the option to |
a <type> option cannot have choices |
| only string, integer and number options accept choices |