DiSky DiSky v5.0.0-b1

Command builders

guide

Building slash, user and message commands as plain objects instead of structures, and mixing the two.

commandsapplication-commandsbuilders

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.

expression new slash commandSlash Command[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.Slash Commandsince 5.0.0-a2

Answering a built command

A builder-declared command has no trigger of its own, so it's answered in the generic , 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

"slash", "user" or "message", read-only

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 slashoption

empty

a list of subcommand

empty

a list of subcommandgroup

Property (slashoption)

Default

Accepted values

the text given at creation

any text

fixed by how it was created

read-only

false

true / false

false

true / false; string, integer and number options only

none

up to 25 slashchoice; string, integer and number options only

none

a number; integer and number options only

none

a number; integer and number options only

none

0 to 6000; string options only

none

1 to 6000; string options only

empty (any channel)

a list of channel types; channel options only

expression new slash optionSlash Option[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.Slash Optionsince 5.0.0-a2

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.

expression new subcommandSubcommand[a] new sub[ ]command (named|with [the] name) %string% with [the] desc[ription] %string%Creates a subcommand. Same naming rules as a slash command.Subcommandsince 5.0.0-a2

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 'sub_command_group')

a new option was built with a structural type instead of an actual subcommand / subcommand group

build a subcommand or subcommand group object, not an option

a <type> option cannot have autocomplete

auto complete was set to true on a boolean, user, channel, role, mentionable or attachment option

only string, integer and number options support autocomplete

only integer and number options have a minimum value (same wording for maximum)

min value / max value was set on a non-numeric option

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 slashchoice's value doesn't match its option's type

give the choice a numeric value, or switch the option to string

a <type> option cannot have choices

choices was set on a boolean, user, channel, role, mentionable or attachment option

only string, integer and number options accept choices

Application Command type 9 syntaxes A slash, user or message command as Discord sees it: what 'update the discord commands' and 'register the discord command' push, and what 'registered commands of' brings back. Made by 'a new slash/user/message command', by the 'slash command' / 'user command' / 'message command' structures (read them back with 'structured slash command "name"'), or retrieved from Discord.
Was this page helpful?
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.