Templating
How AntiRaid's Luau scripting engine works — execution model, sandboxing, and the full API reference.
AntiRaid lets server owners write custom automation logic using Luau — the same Lua variant used in Roblox, with better performance and robust sandboxing. Templates run in a fully isolated VM per guild, with access to Discord events and a set of built-in plugins.
Why Luau?
Luau is a good fit for user-facing scripting because:
- It's well-documented and widely known (especially among Discord server owners familiar with Roblox)
- It's significantly faster than standard PUC Lua
- It supports proper sandboxing — templates can't access anything they aren't explicitly given
How templates work
When an event fires (a member joining, a message being sent, etc.), AntiRaid dispatches it to the template worker, which runs your Luau script inside the guild's VM. Every template receives two arguments:
local evt, ctx = ...evt— the event data (what happened)ctx— the template context (access to plugins like Discord, key-value storage, etc.)
The VM persists between events — you don't pay initialization cost on every run. It's only recycled if it crashes or exceeds memory limits.
Execution limits
| Limit | Value |
|---|---|
| Max memory per VM | 20 MB |
| Max VM stack size | 20 MB |
| Max execution time | 10 minutes |
| Max time before return is ignored | 60 seconds |
These are designed to be generous for legitimate use. Consistent abuse may result in limits being reduced.
Plugins
Templates access AntiRaid features through plugins via the ctx object and the require statement:
local discord = require "@antiraid/discord"
local kv = require "@antiraid/kv"Key plugins include:
ctx.Discord— send messages, manage members, interact with the Discord APIctx.KV— persistent key-value storage scoped to your guild@antiraid/interop— type conversion helpers for Rust/Lua FFI