Skip to content

Message recipes

These examples work in Kit content, a Text Display or a Source response. Each recipe explains the input it needs; the results use Anya as the example user.

Combine @user.name with @channel to greet the person running the Kit and point them to the current channel:

Hi @user.name!
You are in @channel.

Result:

Hi Anya!
You are in <#200>.

In Discord, the second line contains a mention of the invocation channel. The number 200 is the example channel ID used to show the output.

Create an optional text argument named topic, then use ?? to choose a topic when the argument is not supplied:

Topic: $(@args.topic ?? "General")

Result:

Topic: General

Here the argument was not supplied, so the message uses “General”. An argument containing empty text stays empty, because ?? replaces only missing values (nil).

Use the index from $each to number a list of instructions. The index starts at zero, so add one when displaying it:

$each(["Read the rules", "Introduce yourself"] as @step, @index)
$(@index + 1). @step
$end

Result:

1. Read the rules
2. Introduce yourself

Replace the list’s text with instructions for your server. To use a list supplied by the context, replace the bracketed list with its reference.

Set the total before the loop so that each pass adds to the same variable:

$set(@total, 0)
$each([5, 10, 15] as @value)
$set(@total, @total + @value)
$end
Total: @total

Result:

Total: 30

The three passes add 5, 10 and 15 to the outer variable, reaching 30. Keep the calculation and Total: @total in the same field, since local variables do not carry over between fields.

Add a String Select to a workshop Kit with options named News and Chat. Set their values to news and chat, and allow up to two selections. Open Source on that menu and paste this reply:

$set(@rooms, { news: "Room 1", chat: "Room 2" })
$each(@values as @choice)
$(@rooms[@choice] ?? "Ask at the desk")
$end

Result:

Room 1
Room 2

@values contains the values the reader picked. The map pairs each value with a room. You can rename News to Announcements and leave its value as news, so the same reply still works. To add another topic, give it an option value and a key in the map. A value without a room uses “Ask at the desk”.

Split pasted text, keep one entry per topic, then sort and join it for display. $slice can take the first few results using the same zero-based indexes as a list.

$set(@topics, $unique($split($trim(" Music,Art,Music "), ",")))
$join($sort(@topics), " · ")

Result:

Art · Music