Luau Reference
Everything Points adds to Luau, including inputs, triggers, members, the bank, messages and storage, with arguments and return values.
Amounts are always whole numbers. IDs for members, roles and channels are strings, like "123456789012345678". Anything that takes a member also accepts a member object.
Inputs
points.input.<type>(name, label, options?)
Declares a value each server fills in when it installs the automation. Call these at the top level.
| Function | Value in points.inputs |
|---|---|
points.input.channel | Channel ID |
points.input.role | Role ID |
points.input.member | Member object |
points.input.number | Number |
points.input.integer | Whole number |
points.input.text | String |
points.input.boolean | true or false |
points.input.choice | The chosen string |
| Option | Applies to | Meaning |
|---|---|---|
required | all | Defaults to true. An install missing a required input doesn't run. |
default | all | The value used until a server changes it |
min, max | number, integer | Allowed range |
maxLength | text | Longest allowed text |
choices | choice | A list of up to 25 strings. Required. |
Names follow the usual rules: 1 to 32 lowercase letters, numbers, - and _. Labels can be up to 100 characters.
points.input.channel("announcements", "Where to post results")
points.input.number("rate", "Tax rate in percent", { default = 5, min = 0, max = 100 })
points.input.role("taxed", "Who pays the tax", { required = false })points.inputs
A read-only table of the install's values, by input name. Optional inputs a server left empty are nil.
local filter = points.inputs.taxed and { role = points.inputs.taxed } or {}Triggers
points.schedule(name, config, handler)
Runs handler(ctx) at the times in config.cron.
| Field | Meaning |
|---|---|
cron | A five-part cron expression. See Schedules. |
timezone | An IANA timezone like "America/New_York". Defaults to "UTC". |
ctx.name is the schedule's name, and ctx.scheduledFor is when the run was meant to happen.
A script can have up to 10 schedules.
points.command(definition, handler)
Adds a slash command to the server and runs handler(ctx) when someone uses it.
| Field | Meaning |
|---|---|
name | 1 to 32 lowercase letters, numbers, - and _ |
description | 1 to 100 characters |
permission | "everyone" (default), "moderator" or "admin" |
cooldown | Seconds each member must wait between uses, up to 86400. Defaults to 0. |
options | Up to 25 options, made with points.option |
A script can have up to 10 commands.
The command's ctx has:
| Field | Meaning |
|---|---|
ctx.member | Member object for the person who used the command |
ctx.channelId | ID of the channel it was used in |
ctx.options | Option values by name. Member options are member objects, role and channel options are IDs. Optional options left empty are nil. |
ctx:reply(message, options?) | Replies to the member. Pass { ephemeral = true } to make it visible only to them. |
points.option.<type>(name, description?, options?)
Makes a command option.
| Function | Value in ctx.options |
|---|---|
points.option.user | Member object |
points.option.role | Role ID |
points.option.channel | Channel ID |
points.option.integer | Whole number |
points.option.number | Number |
points.option.string | String |
points.option.choice | The chosen string |
Options take required (default true), min and max for numbers, maxLength for strings, and choices for choice options (up to 25, each 1 to 100 characters).
points.option.integer("amount", "How much", { min = 1, max = 10000 })
points.option.choice("side", "Heads or tails", { choices = { "heads", "tails" } })Members
points.getMember(id)
Returns a member object, or nil if the member isn't in the server.
Member objects
| Field | Meaning |
|---|---|
member.id | The member's ID |
member.balance | Their balance, kept up to date as the script changes it |
member.roles | A list of their role IDs |
| Method | Does | Returns |
|---|---|---|
member:add(amount) | Adds points | New balance |
member:subtract(amount) | Takes points. Fails if they don't have enough. | New balance |
member:set(amount) | Sets their balance | New balance |
member:pay(other, amount) | Moves points to another member. Fails if they don't have enough, or if other is themselves. | Their new balance |
member:hasRole(roleId) | Checks a role | true or false |
member:addRole(roleId) | Gives a role | Nothing |
member:removeRole(roleId) | Removes a role | Nothing |
member:items() | Lists their shop items | A list of { id, name, quantity } |
member:giveItem(itemId, quantity?) | Gives a shop item, up to 100 at once. Defaults to 1. | Nothing |
member:takeItem(itemId, quantity?) | Takes a shop item. Fails if they don't have enough. | Nothing |
Roles with moderation or admin permissions, roles managed by an integration, and @everyone can't be given or removed.
To find a shop item's ID, add a Give an item block, pick the item, then switch to Code.
Groups of Members
points.members(filter?)
Returns a query for every member that matches the filter. Leave it out to match everyone.
| Filter | Matches members who |
|---|---|
role | Have this role ID |
minBalance | Have at least this many points |
maxBalance | Have at most this many points |
hasItem | Own this shop item ID |
Bulk methods change every matching member in one go, with no limit on how many. They return { count, total }: how many members changed and how many points moved.
| Method | Does | Returns |
|---|---|---|
query:add(amount) | Adds to each member | { count, total } |
query:subtract(amount) | Takes from each member, stopping at 0 | { count, total } |
query:set(amount) | Sets each member's balance | { count, total } |
query:tax(rate) | Moves a share of each positive balance into the bank. rate is between 0 and 1, so 0.05 is 5%. | { count, total } |
query:count() | Counts the members | Number |
query:sum() | Adds up their balances | Number |
query:list(limit?) | Loads members, highest balance first. Defaults to 100. | List of member objects |
query:each(fn) | Calls fn(member) for each member, highest balance first, up to 1,000 | Nothing |
local result = points.members({ minBalance = 1000 }):tax(0.05)
print(`Taxed {result.count} members for {result.total} points`)The Bank
| Function | Does | Returns |
|---|---|---|
points.bank.balance() | Reads the server bank | Number |
points.bank.add(amount) | Adds points to the bank | New bank balance |
points.bank.subtract(amount) | Removes points. Fails if the bank doesn't have enough. | New bank balance |
points.bank.pay(member, amount) | Pays a member from the bank. Fails if the bank doesn't have enough. | New bank balance |
Messages
points.send(channelId, message, options?)
Posts in a channel of the server. Messages mention members but never roles, @everyone or @here. Pass { mentions = "roles" } to let role mentions ping too.
points.log(message)
Sends to the server's log channels that include the Automations log type. Does nothing if there aren't any.
Message format
A message can be a string, an embed table, or a table with content and embed.
points.send(channelId, "Plain text")
points.send(channelId, {
title = "Season over",
description = "Balances have been reset.",
color = 0x0695F1,
fields = {
{ name = "Winner", value = "<@123456789012345678>", inline = true },
{ name = "Prize", value = "5,000 points", inline = true },
},
footer = "See you next month",
})
points.send(channelId, { content = "<@123456789012345678>", embed = { title = "You won" } })| Embed field | Meaning |
|---|---|
title | Title text |
description | Main text |
color | Color as a number, like 0x0695F1 |
fields | A list of { name, value, inline? } |
footer | Footer text |
image | URL of a large image |
thumbnail | URL of a small image |
Use <@id> to mention a member, <@&id> for a role and <#id> for a channel. A run can send up to 5 messages, counting replies and log posts.
Storage
Storage keeps values between runs. Each install has its own storage, so two servers running the same automation don't share it.
| Function | Does | Returns |
|---|---|---|
points.storage.get(key) | Reads a value | The value, or nil |
points.storage.set(key, value) | Saves a value: a string, number, boolean or table of those | Nothing |
points.storage.increment(key, amount?) | Adds to a whole number, starting from 0. Defaults to 1. | The new value |
Each value can be up to 16 KB, and an install can store up to 1,000 keys. Storage changes are undone if the run fails, like everything else.
Output
print(...) writes a line to the run's output, which appears in test results and run history. A run keeps up to 100 lines.
error(message) stops the run and undoes everything it changed.