RobertScript, the scripting language
Program your own features for your server with a simple language, in English or French: mini-games, points, polls, buttons, timers, storage.
On this page
Your first script Language basics Variables and valuesTexts and bracesConditionsLoopsFunctionsErrorsEnglish or French Triggers Buttons and menus Provided variables Standard library Discord actions Storage AI and web requests (optional) Safety and limits Discord commands ExamplesRobertScript is Robert's scripting language. It reads like pseudo-code, is written in English or French (you can even mix both), and lets you build what no module does on its own: a mini-game, a points system, a poll with buttons, a role given under conditions, a birthday message…
points = storage.incr("points:" + member.id)
if points == 10 then
reply("🎉 Well done {member.mention}, you reached 10 points!")
else
reply("{member.name} has {plural(points, 'point')}.")
end
Network plan
Advanced RobertScript (functions, loops, storage, buttons, timers, AI, web) is part of the Network plan. The simple conditions of custom commands and variables such as {user.mention} stay available to everyone, for free. The editor and the “Test” button open on every plan: you can try before you subscribe.
Your first script
- In the dashboard, open Configuration › RobertScript.
- Click New script and pick a template (or “Blank script”).
- Choose the trigger (for instance “Command” named
hello). - Write the code, then press Test (or
Ctrl+Enter): the script runs in a sandbox, nothing is sent to Discord. - Save (
Ctrl+S) and enable the module with the switch at the top of the page.
The editor highlights the code, numbers the lines, suggests functions as you type (Ctrl + Space to force suggestions) and reports errors live, with their line and column. Click an error to jump to it.
Language basics
Variables and values
Store a value in a variable with =:
name = "Lea" # text (between quotes)
age = 12 # number
registered = true # boolean: true / false
nothing = nil # no value
colors = ["blue", "white", "red"] # list
profile = {name: "Lea", points: 3} # dictionary
Comments start with # (or //). x += 1 adds 1 to x (also -=, *=, /=).
Texts and braces
In a double-quoted text, {…} is replaced with the value of the expression: "Hi {name}, you'll be {age + 1} next year". The Robert variables you already know work too: {user.mention}, {server}, {member_count}, {robert.dashboard}, {random:heads|tails}… To write an actual brace, double it: {{ and }}. Single-quoted texts ('…') are never interpreted.
Safe by design
Only the code you write is interpreted. A member's text (their message, their nickname) is never executed, even if it contains braces.
Conditions
if points >= 100 then
reply("Legend!")
elif points >= 10 then
reply("Regular")
else
reply("Newcomer")
end
Operators: == (equal), != (different), <, <=, >, >=, and, or, not, in (“"admin" in roles”), not in. Arithmetic: +, -, *, /, % (remainder). "ab" * 3 repeats a text.
= or ==?
A single = stores a value, two == compare. The editor warns you if you write if x = 3.
Loops
for i from 1 to 5 do
print(i)
end
for each name in ["Lea", "Hugo"]
print("Hello " + name)
end
for key, value in profile
print(key + " = " + value)
end
n = 0
while n < 3 do
n += 1
end
break leaves the loop, continue skips to the next round. then and do are optional.
Functions
func stars(n)
return "⭐" * n
end
reply("Rating: " + stars(4))
Variables created in a function stay local to it. A function can call itself (40 nested calls at most).
Libraries: a script whose trigger is “Function library” never runs on its own; its functions can be called from every other script of the server.
Errors
try
add_role(member, "VIP")
catch err
reply("Not possible: " + err.message)
end
error("message") stops the script with your own message. Safety limits (endless loop, memory…) can't be caught.
English or French
Every keyword and function has two names, which you can mix:
| English | French |
|---|---|
if … then … elif … else … end |
si … alors … sinon si … sinon … fin |
for i from 1 to 10 step 2 do |
pour i de 1 à 10 pas 2 faire |
for each x in list |
pour chaque x dans liste |
while … do |
tant que … faire |
func f(a) … return a … end |
fonction f(a) … retourne a … fin |
and, or, not, true, false, nil |
et, ou, non, vrai, faux, rien |
break, continue, try … catch |
arrête, continuer, essayer … attraper |
Lists start at index 0 (list[0]) and list[-1] is the last item.
Triggers
| Trigger | When the script runs | Useful variables |
|---|---|---|
| Command | !name arguments (server prefix) or /script run command:name |
member, channel, message, args, args_text |
| Message | a message contains, starts with, exactly equals a pattern, or matches a regular expression | member, channel, message |
| Reaction | a reaction (a given emoji or any) is added | member, channel, event.emoji |
| Button or menu | a click on a button created by a script, by its ID | event.id, event.values |
| Member joins / leaves | a member joins or leaves the server | member, channel (channel picked for the script) |
| Timer | 20:00 daily, every 2h, or cron 0 20 * * 1-5 (server time zone, every 5 minutes at most) |
server, channel |
| Library | never on its own: shared functions | — |
Buttons and menus
A script creates buttons with button(id, label, style, emoji); a click calls its on_button(id) function (sur_bouton in French). For a select menu, select_menu(id, options) and on_select(id, values).
reply({content: "Coming tonight?", buttons: [button("yes", "Yes", "success"), button("no", "No", "danger")]})
func on_button(id)
storage.set("answer:" + member.id, id)
reply({content: "Noted: " + id, ephemeral: true})
end
When a button is clicked, only the on_button function runs (not the rest of the script): keep in storage whatever must survive between two clicks.
Provided variables
| Variable | Content |
|---|---|
member (user, membre) |
id, name, username, mention, avatar, roles (IDs), bot, joined and created (timestamps) |
server (serveur) |
id, name, member_count, boosts, icon, owner_id |
channel (salon) |
id, name, mention, topic, parent_id, type |
message |
id, content, channel_id, author_id, url |
args, args_text |
command arguments (list, and full text) |
event (evenement) |
type and the trigger details (emoji, button id, menu values…) |
robert |
site, dashboard, docs, pricing, invite |
Writing an object in a text shows its name ({member}, {server}) or its mention ({channel}).
Standard library
Text: len, upper, lower, capitalize, trim, replace(text, old, new), split(text, sep), join(list, sep), starts_with, ends_with, contains, index_of, slice(x, start, end), repeat, format_number(1234567) → “1,234,567”, plural(3, "point") → “3 points”, mention(id), channel_mention(id), role_mention(id).
Lists and dictionaries: push(list, value), insert, remove, sort(list, descending), reverse, unique, first, last, range(1, 10), keys, values, sum, min, max, copy. They also work as methods: list.push(4), name.upper().
Numbers: number("3.5"), int, round(x, decimals), floor, ceil, abs, sqrt, pow, and math.pi.
Random: random(1, 6), choice(list), shuffle(list), seed(n) (same draws on every run, handy for a “draw of the day”).
Dates (server time zone): now() (seconds), date() → year, month, day, hour, minute, weekday (1 = Monday), day_name, month_name; format_date(t, "DD/MM/YYYY HH:mm"), discord_time(t, "R") (date shown by Discord in each reader's time), duration("1h30") → 5400, format_duration(5400) → “1h 30m”.
JSON: to_json(value), from_json(text).
Misc: print(…) (log only, nothing is sent), type(x), str(x), error(message).
Discord actions
| Function | What it does |
|---|---|
reply(content) |
replies to the message, command or click that started the script |
send(channel, content) |
sends a message in a channel of the server |
dm(content) |
direct message to the member who triggered the script |
react(emoji, message) |
adds a reaction (to the triggering message by default) |
add_role(member, role), remove_role(member, role) |
role by ID, mention or exact name |
has_role(member, role) |
true if the member has this role |
create_thread(name, message) |
creates a thread |
delete_message() |
deletes the triggering message |
wait_reply(seconds, from_anyone) |
waits for the member's next message (60 s at most) |
get_member(id), get_server(), get_channel(id), get_role(id_or_name) |
up-to-date information |
A content is a text, or a dictionary: {content: "…", embed: embed("Title", "Text", "#2346d4"), buttons: […], menu: select_menu(…), ephemeral: true}. An embed also accepts image, thumbnail, footer, author, url and fields: [{name, value, inline}]. ephemeral (only visible to the person) works for replies to slash commands and clicks.
Storage
Each server has a key-value storage shared by all its scripts:
storage.set("weather", {city: "Lyon", degrees: 18})
w = storage.get("weather", {})
total = storage.incr("points:" + member.id, 5)
top = storage.top("points:", 10) # [{key, value, rank}, …]
storage.keys("points:") # 100 keys at most
storage.delete("weather")
A value is 4 KB at most (text, number, list, dictionary). The number of keys depends on the plan (10,000 on Network).
AI and web requests (optional)
Two module settings, off by default, unlock AI and the web:
ai.ask(prompt, instructions)asks Robert's AI and returns its answer. Each call uses one AI credit of the subscription (3 calls at most per run).http.get(url, headers)andhttp.post(url, body, headers)call a public https address: never the local network or a private address, 5-second timeout, 256 KB response at most, 3 requests per run. The result hasstatus,bodyandjson. An allowed domains list restricts calls to your own APIs.
Safety and limits
Each script acts with Robert's permissions and its author's (the member who last saved it): it can't do anything its author couldn't do. If the author leaves the server, the script can't act until a manager saves it again.
- A script never gives or removes a role with sensitive permissions (administrator, manage server, roles, channels, ban, kick, mention @everyone…), and respects the role hierarchy.
- Messages only notify the members mentioned: never
@everyone,@hereor a role. - A setting restricts the channels where scripts can write.
- No access to files, the system or the network beyond the functions above.
| Limit per run | Value |
|---|---|
| Computing time | 100 ms (waiting for replies, AI and web don't count) |
| Instructions | 200,000 |
| Memory | 8 MB |
| Nested calls | 40 |
| Discord actions | 15 |
| Script size | 20,000 characters |
| Network plan limit | Value |
|---|---|
| Scripts | 100 |
| Runs | 120 per minute (5 scripts at the same time at most) |
| Storage keys | 10,000 |
A script that fails several times in a row (10 by default, adjustable) is disabled automatically; an alert goes to the errors channel if one is set.
Discord commands
| Command | Purpose |
|---|---|
/script list |
the server's scripts, their state and statistics |
/script enable · /script disable |
enables or disables a script |
/script test script:… text:… |
runs a script in the sandbox with your real information: nothing is sent |
/script log |
latest runs and their errors |
/script run command:… text:… |
runs a “command” script as a slash command |
The dashboard log (Log tab of the editor) keeps 7 days of runs: duration, actions, line and message of each error, and the lines written with print.
Examples
Guessing game
secret = random(1, 20)
reply("Guess my number between 1 and 20!")
for try_number from 1 to 3
answer = wait_reply(30)
if answer == nil then
reply("Too late! It was {secret}.")
return
end
if number(answer.content) == secret then
reply("You won in {plural(try_number, 'try', 'tries')}!")
return
end
reply(hint(number(answer.content), secret))
end
reply("You lost, it was {secret}.")
func hint(n, secret)
if n == nil then
return "Write a number!"
end
if n < secret then
return "Higher ⬆️"
end
return "Lower ⬇️"
end
Reaction role after 7 days on the server (trigger “Reaction”, emoji ⭐)
days = (now() - member.joined) / 86400
if days >= 7 then
add_role(member, "VIP")
else
dm("The VIP role is available after 7 days on the server.")
end
Monday announcement (trigger “Timer”, 0 9 * * 1)
week = int((now() - 1767225600) / 604800) + 1
send(channel, {embed: embed("Have a great week!", "Week #{week} — the schedule is on {robert.dashboard}", "#1f9d55")})
The editor templates (guessing game, counting channel, points system, poll, reaction role, birthdays, welcome with a button) are good starting points: open them, test them, then adapt them.
Spotted a mistake? Got a question? Let us know on the support server.