Macro slashy::command[][src]

command!() { /* proc-macro */ }
Expand description

Macro to create commands.

Command macro format

command!{
    name,
    description,
    function,
    [
        required Type name = function | "description" {choices: map} [children]
    ]
}

Argument Types

  • Integer (u32)
  • Str (String)
  • Boolean (bool)
  • User (UserId)
  • Channel (ChannelId)
  • Role (RoleId)
  • SubCommand
  • SubCommandGroup

Type Specific Fields

The fields children, choices, and function are all only valid for some of the argument types.
Only SubCommand and SubCommandGroup arguments can have function or children.
And only Integer and Str can have choices.

SubCommands

SubCommands allow you to have multiple paths to your command.

By including a function when defining a SubCommand that function will be run when the SubCommand is given.

SubCommands can also have child arguments and their functions will only be run when all required arguments are present.

Examples

stats get|set [user]

command!{
    stats,
    "get or set a user's stats",
    [
        optional SubCommandGroup get | "get info about stats" [
            optional SubCommand points = points | "get a user's points" [
                optional User user | "the user whose points you want to get"
            ],
            optional SubCommand credits = credits | "get a user's credits" [
                optional User user | "the user whose points you want to get"
            ]
        ],
        optional SubCommand set = set_stats | "set a user's stats"
    ]
}

add a b

command!{
    add,
    "adds two numbers",
    add,
    [
        required Integer a | "the first number to add",
        required Integer b | "the second number to add"
    ]
}

grid size with choices of 1, 5, and 12

command!{
    grid,
    "prints a grid",
    grid,
    [
        required Integer size | "the size of the grid" {"small": 1, "medium": 5, "large": 12},
    ]
}

You have to follow all the rules of normal discord slash commands.
This includes not allowing required arguments after optional ones.

command!{
    test,
    "testing",
    test
   [
       required Integer test | "the first argument",
       optional String test2 | "the second argument",
       required String test3 | "the third argument" // Fails to compile
    ]
}