Introduction
How code runs
Section titled “How code runs”A custom command written in code is a piece of text. When someone uses the command, Petto:
- Reads the code and checks it. A mistake stops everything before anything is sent, and says the line and the column.
- Runs it with the data of that moment: who used the command, in which server and channel, with which arguments.
- Collects two things: the text the code printed, and the actions it asked for (send a message, give a role…).
- Does the actions, only the ones it is allowed to do, and sends the text.
The code never talks to Discord by itself. A function such as sendMessage does not send anything while the code runs:
it adds an action to the list, and Petto decides at the end whether to do it. That is why the same code can be tested in
the dashboard without sending anything.
What is printed
Section titled “What is printed”Everything outside {{ }} is printed as it is. Inside {{ }}, an action that has a value prints it:
Your name is {{ .User.Username }}.An action that does something, such as {{ sendMessage nil "hi" }} or {{ $x := 1 }}, prints nothing.
If the code printed text, Petto sends it as the answer of the command. If it printed nothing, only the actions are done.
What it cannot do
Section titled “What it cannot do”- It cannot read or write files, call a web page, or reach anything outside the data it is given.
- It cannot run forever: it has limits of steps, time, loops and actions (Limits).
- It cannot ping
@everyoneor@here, and it only pings the roles and users it mentions on purpose.
Who can use it
Section titled “Who can use it”While custom commands in code are in testing, only Petto’s team can write them. They will open to servers later, and it is likely to be a Premium feature with different limits for Free and Premium.
