Commands, arguments and events
Command settings
In the dashboard you fill these in on the command’s settings panel. In a command file they’re the lines above ---, one per line. Paste a whole file into the code editor and the settings at the top are moved into the settings panel for you, so files from these docs, an AI or a friend just work. Copy file in the editor does the reverse, for sharing.
| Setting | What it is |
|---|---|
command: name | The command people type, like /pay. Lowercase letters, numbers, - and _, up to 32 characters. |
description: … | The short explanation Discord shows under the command (up to 100 characters). |
arg name: type, required, description | One line per argument, up to 10. Types: text, number, user, channel, role, bool. Write required or optional; required ones come first. Text and number arguments can also have choices a | b | c (Discord shows a list to pick from) or min/max. |
permissions: kick_members | Who can run it: the Discord permissions the person needs. Discord hides the command from everyone else. |
roles: VIP, Moderator | Who can run it: people with at least one of these roles. |
allow: balances, storage | What the script is allowed to do, like change coins or save data. See allowed actions. |
cooldown: 5 | Seconds each person waits between uses (default 3). |
mode: both | slash, prefix or both. Leave it out to match your bot’s other commands. |
Starting variables
Every script starts with a few variables already set, describing who ran it and where:
user: whoever triggered the script.member: the same person as a member of this server (roles, nickname, joined_at).server: this server.channel: the channel it happened in.args: the command’s arguments, by name (commands only).message: the message (prefix commands and message automations).event: details of what happened (automations only).
Arguments
Each argument you add in the settings is args.name in the script. An optional argument nobody filled in is none.
command: pay
description: Pay someone coins
arg to: user, required, Who to pay
arg amount: number, required, min 1, How many coins
allow: balances
---
amount = floor(args.amount)
if args.to == user:
fail("You can’t pay yourself.")
if economy.balance(user) < amount:
fail("You don’t have {amount} coins.")
economy.take(user, amount, "pay to {args.to.name}")
economy.give(args.to, amount, "pay from {user.name}")
reply("💸 {user.mention} paid {args.to.mention} **{amount}** coins.")What you can read
| Thing | Details you can read |
|---|---|
| user | id, name, display_name, mention, avatar, bot, created_at |
| member | id, name, display_name, nickname, mention, avatar, bot, created_at, joined_at, roles, permissions, is_owner, status, activity, user |
| server | id, name, icon, owner_id, member_count, boosts, boost_level, channel_count, role_count, created_at |
| channel | id, name, mention, type, topic, nsfw |
| role | id, name, mention, color, position, member_count |
| message | id, content, author, channel, link, created_at |
| embed | title, description, color, url, image, thumbnail, footer, author, fields |
| error | message, code, line |
Times (created_at, joined_at, now()) are in seconds since 1970. Turn them into a nice time with format_time(). A person, channel or role put in text becomes a mention: "Hi {user}" pings them, "{user.name}" just shows the name.
Automations
An automation is a script that runs by itself when something happens, instead of when someone types a command. Make one in Scripts → Automations. Its file says event: instead of command:, and it has no arguments, permissions or mode. Instead of args, it gets event with the details.
| Setting | What it is |
|---|---|
event: message | What it runs on (the events are below). |
description: … | Its name in your lists and in /modules automations. |
channels: general, memes | Messages and reactions: only in these channels. |
contains: hello, good morning | Messages: only when the text contains one of these (any case). |
emojis: ⭐, 👍 | Reactions: only these emojis. |
roles: VIP | Role events: only these roles. |
cooldown: 30 | Seconds before it runs again for the same person (default 0). |
allow: … | What the script may do, like commands. |
Automations are built so they can’t cause trouble:
- They never run for bots, and changes your bot’s own scripts make (roles, kicks, timeouts, bans) never start them, so they can’t set each other off in a loop. One that runs too often in a server pauses itself for a minute.
- They act as the bot, with nobody to check: they can’t give out roles with staff permissions, kick or time out staff, ban, purge, delete channels or roles, or change server settings. Use a command for those.
- They can make at most 25 channels, threads and roles per server per day.
reply()answers the message for message and reaction automations. The others post withsend().- Problems go to the run log, never into the server.
- Server admins can turn all automations off with
/modules, or one at a time with/modules automations.
| Event | When | What the script gets |
|---|---|---|
member_join | A member joins | user and member are the person who joined. channel is the server’s system channel (or none). |
member_leave | A member leaves | user is the person who left. member has no roles any more. channel is the server’s system channel (or none). |
message | A message is sent | message is the message, user its author, channel where it was sent. |
reaction_add | A reaction is added | message is the message, user who reacted, event.emoji the emoji, channel where. |
role_add | Someone gets a role | user and member are who got it, event.role the role. channel is the system channel (or none). |
role_remove | Someone loses a role | user and member are who lost it, event.role the role. channel is the system channel (or none). |
event: member_join
description: Welcome new members
allow: channels
---
room = get_channel("welcome")
if room != none:
send(room, "Welcome {user.mention}! You’re member #{server.member_count} 🎉")