Tutorials

Interactive Messages

Build a custom command with durable buttons and fresh Lua runs.

Published by solever7 solever7
tutorial components buttons stateless

This tutorial turns a plain custom command into a small menu. Each click reloads the
same script in a fresh Lua session and calls the function named by the button. Macchi
stores a route to the function, never a Lua closure or a live session.

Create The Command

Create a personal custom command named guide, then use Edit source and paste:

function rules()
  macchi.reply("Read the rules before posting.")
end

function help()
  macchi.reply("Ask a moderator if the guide does not answer your question.")
end

function run()
  message.new()
    :text("What do you need?")
    :button("rules", "Rules")
    :button("help", "Help")
    :send()
end

Run the command and click both buttons. run builds the message. rules and help
are normal Lua entries loaded later for the person who clicks.

Keep The Route Valid

  • Function names must match the first argument passed to :button.
  • The published version or current draft is pinned into the component route.
  • The clicking person, server, channel, and route are validated before Lua runs.
  • Message and component objects are inert until :send() or
    macchi.replyMessage(message) is called.

Do not keep state in a global variable between clicks. If the workflow needs durable
values, use the storage API with an explicit capability and scope.

Continue

Use the Lua API for button styles, selects, and message builders.
For automatic behavior in one channel, continue with Channel
Automation
.