Control Flow
defer
$defer
$defer acknowledges the interaction and marks it as acknowledged in the execution state. For most scripts it is not needed to give more than 3 seconds: the engine already acknowledges the interaction itself before running the script. It matters for the scripts that are not acknowledged beforehand (see below).
Syntax
$defer
$defer[ephemeral]
| Parameter | Description |
|---|---|
ephemeral |
Optional. yes or true records that the deferred response is ephemeral; any other value is ignored (no error). |
$defer takes 0 or 1 argument and returns an empty string.
What the engine does
- Before running a script for an interaction, the executor acknowledges the interaction automatically, except when the script contains
$newModal,$callWorkflow,$evalor$funcCall(a modal must be the first response). In those scripts,$deferacknowledges the interaction itself: without it nobody would acknowledge, and the interaction token would expire after 3 seconds. The acknowledgement is ephemeral with$defer[yes]or when the script contains$ephemeral. If Discord refuses it, the error isCould not defer the interaction: <cause>. - In every case
$defersets three flags in the execution state: the interaction is acknowledged, a defer was requested, and (withyes/true) the response is ephemeral. Its position in the script does not matter. In a script that was already acknowledged beforehand, or in a host that owns no interaction (such as the sandbox), it only sets these flags. - Because
$defermarks the interaction as acknowledged,$newModalcalled after it fails withModal must be the first interaction response.
Example
$defer
$wait[1s]
Done!
The text is sent when the script ends.
Notes
- Calling it several times has no additional effect.
- To make the response ephemeral, use
$ephemeral.
Try it
Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.