Defining a command
command pay(target: player, amount: int, note: text = "no note"):
permission "shop.pay"
aliases "give", "transfer"
description "Pays another player"
usage "/pay <player> <amount> [note]"
send "You paid {target.name} {amount} ({note})" to sender
The arguments are parsed and checked before your code runs. Bad input and missing arguments are answered with a usage message automatically, and typed arguments tab-complete.
Argument types
| Type | Accepts |
|---|---|
number |
any number, 2.5 |
int |
a whole number |
word |
one word |
text |
the rest of the line (must be the last argument) |
bool |
true / false, yes / no, on / off |
player |
an online player’s name |
world |
a world name (Paper) |
server |
a backend server name (Velocity) |
An argument with a default value is optional: target: player = sender uses whoever ran the command. Addons can add more argument types.
Inside a command
senderis whoever ran the command: a player or the console.sender.is_playertells which.argsis the raw list of words, for commands that parse their own input.
command fly(enabled: bool):
if not sender.is_player:
send "<red>Only players can fly." to sender
return
sender.can_fly = enabled
Options
| Option | Effect |
|---|---|
permission "x.y" |
only senders with this permission can run it |
aliases "a", "b" |
other names for the command |
description "..." |
shown in /help |
usage "..." |
replaces the generated usage message |
executor "player" |
only players (or "console": only the console) |
cooldown 30 seconds |
per-sender cooldown |
cooldown_message "..." |
message while on cooldown; {time} is the time left |
command heal:
executor "player"
cooldown 1 minute
cooldown_message "<red>You can heal again in {time}."
sender.heal()
Options go at the top of the command, before the code. Two scripts cannot define the same command; the second one gets a load error.
For cooldowns on anything other than a whole command, use the cooldowns module.