Text, list, and number functions
Call a function directly in a message, as in $upper("workshops"), or use the same call inside $set, a condition, or $(...). The generated signatures show which arguments you can omit. Use operators to combine lists with +, count with #, or check membership with in.
Prepare text for a message
Section titled “Prepare text for a message”Say a workshop form gives you a comma-separated list of topics. Split the string, trim each topic, and join the cleaned labels for Discord.
$set(@topics, [])
$each($split("music, drawing, film", ",") as @topic) $set(@topics, @topics + $trim(@topic))$endTopics: $join(@topics, " · ")Result:
Topics: music · drawing · film$upper(text)
Section titled “$upper(text)”(String) → String · Pure
Converts text to uppercase. $upper("saturday") produces SATURDAY. The conversion uses the same rules in every interface language.
$lower(text)
Section titled “$lower(text)”(String) → String · Pure
Converts text to lowercase. Write $lower(@args.shift) == "morning" to handle Morning and morning alike. Accents remain part of the text.
$trim(text)
Section titled “$trim(text)”(String) → String · Pure
Removes whitespace from both ends, including tabs and line breaks. $trim(" Room 2 ") returns Room 2 with the space between the words intact.
$replace(text, search, replacement)
Section titled “$replace(text, search, replacement)”(String, String, String) → String · Pure
Replaces every non-overlapping literal match of search with replacement. $replace("day_1_day_2", "_", " ") returns day 1 day 2. Pass "" as the replacement to delete the matches. The search text must be nonempty.
$split(text, separator)
Section titled “$split(text, separator)”(String, String) → List · Pure
Returns a list by splitting on a nonempty literal separator. $split("blue,,green", ",") returns ["blue", "", "green"]. Empty parts stay in the list, so form entries keep their positions.
$slice(value, start, end = nil)
Section titled “$slice(value, start, end = nil)”(Any, Number, Any) → Any · Pure
Takes part of a string or list starting at index zero. The end index is excluded and defaults to the length. Negative indexes count from the end. $slice(["a", "b", "c"], -2) returns ["b", "c"]. Like #, text positions count Unicode scalar values.
$startsWith(text, prefix)
Section titled “$startsWith(text, prefix)”(String, String) → Boolean · Pure
Returns true if the text starts with the exact prefix. $startsWith("wOrkshop", "Wo") is false. Apply $lower to both inputs to compare them without regard to case.
$endsWith(text, suffix)
Section titled “$endsWith(text, suffix)”(String, String) → Boolean · Pure
Returns true if the text ends with the exact suffix. $endsWith("guide.pdf", ".pdf") is true. This checks the filename text. It does not inspect the file.
$join(items, separator = "")
Section titled “$join(items, separator = "")”(List, String) → String · Pure
Formats simple values and puts the separator between them. $join([1, 2, 3], " / ") returns 1 / 2 / 3. Omit the separator to join the values directly. Use $each to choose which parts of nested lists or maps to display.
Organize lists
Section titled “Organize lists”$set(@rooms, [3, 1, 3, 2])Open rooms: $join($sort($unique(@rooms)), ", ")Reverse order: $join($reverse($sort($unique(@rooms))), ", ")Result:
Open rooms: 1, 2, 3Reverse order: 3, 2, 1$sort(items)
Section titled “$sort(items)”(List) → List · Pure
Returns a new list of numbers or a new list of strings in ascending order. String ordering is ordinal and case-sensitive, so "10" comes before "2".
$reverse(items)
Section titled “$reverse(items)”(List) → List · Pure
Returns the list in reverse order. Use $reverse($sort(@rooms)) for descending order. The original list is unchanged.
$unique(items)
Section titled “$unique(items)”(List) → List · Pure
Keeps the first occurrence of each value. $unique(["voice", "text", "voice"]) gives ["voice", "text"]. It follows the equality rules, including comparison of list and map contents.
$range(start, end, step = 1)
Section titled “$range(start, end, step = 1)”(Number, Number, Number) → List · Pure
Builds a list of whole numbers from start up to but excluding end. $range(1, 6, 2) returns [1, 3, 5]. The default step is 1. Use a negative step to count down. A step of zero is invalid, and a long range can exhaust the work budget.
$choice(items)
Section titled “$choice(items)”(List) → Any · Contextual
Picks a random item with the same chance for each position. An empty list returns nil. Save the result with $set(@featured, $choice(@topics)) to display the same draw more than once in a field.
$random(start, end)
Section titled “$random(start, end)”(Number, Number) → Number · Contextual
Draws a whole number from start up to but excluding end. $random(1, 7) rolls a six-sided die. The bounds must increase and fit within −2,147,483,648 to 2,147,483,647. Each call draws again during delivery.
Calculate and display numbers
Section titled “Calculate and display numbers”$set(@total, @args.price * @args.quantity)Total: $$fixed(@total, 2)Bookings per person: $min(@args.quantity, 4)Result:
Total: $6.00Bookings per person: 3$round(number, digits = 0)
Section titled “$round(number, digits = 0)”(Number, Number) → Number · Pure
Rounds to digits decimal places, from 0 to 15, defaulting to 0. Midpoint ties round toward the even digit. $round(1.125, 2) returns 1.12. The result is a number, so trailing zeros may disappear.
$fixed(number, digits = 0)
Section titled “$fixed(number, digits = 0)”(Number, Number) → String · Pure
Returns text with exactly the requested number of decimal places, from 0 to 15. $fixed(12, 2) returns 12.00. The decimal separator is a dot. Use $replace($fixed(12, 2), ".", ",") to display a comma.
$min(left, right)
Section titled “$min(left, right)”(Number, Number) → Number · Pure
Returns the smaller of two numbers. $min(@args.quantity, 4) caps the quantity at four.
$max(left, right)
Section titled “$max(left, right)”(Number, Number) → Number · Pure
Returns the larger of two numbers. $max(@args.quantity, 1) displays at least one. Combine it with $min to keep a result within a fixed range.
$abs(number)
Section titled “$abs(number)”(Number) → Number · Pure
Returns the magnitude of a number without its sign. $abs(-4) returns 4. Use it to display a distance or difference without its direction.
$floor(number)
Section titled “$floor(number)”(Number) → Number · Pure
Rounds toward the lower whole number. $floor(2.9) gives 2, and $floor(-2.1) gives -3. Use it to count complete groups.
$ceil(number)
Section titled “$ceil(number)”(Number) → Number · Pure
Rounds toward the higher whole number. $ceil(2.1) gives 3, and $ceil(-2.9) gives -2. Use it to count pages or tables, including a partial group.
$timestamp(seconds, style = "f")
Section titled “$timestamp(seconds, style = "f")”(Number, String) → String · Pure
Formats whole Unix seconds so Discord can display the date in the reader’s language and time zone. Use t or T for time, d or D for a date, f, F, s, or S for date and time, and R for relative time. The default is f. Seconds range from 0 to 253,402,300,799. @now gives the current execution time in seconds.
The event opens $timestamp(1735689600, "R").Result:
The event opens <t:1735689600:R>.Function results count toward the execution limits even if you store them in a variable. To use information about a person, channel, or Kit, see properties and Kit application.