Skip to content

Introduction

A custom command written in code is a piece of text. When someone uses the command, Petto:

  1. Reads the code and checks it. A mistake stops everything before anything is sent, and says the line and the column.
  2. Runs it with the data of that moment: who used the command, in which server and channel, with which arguments.
  3. Collects two things: the text the code printed, and the actions it asked for (send a message, give a role…).
  4. 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.

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.

  • 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 @everyone or @here, and it only pings the roles and users it mentions on purpose.

Custom commands in code are open to every server: anyone who can manage commands can write them. A Free server can have up to 50 custom commands and a Premium server up to 100.