> ## Documentation Index
> Fetch the complete documentation index at: https://mikting.docs.komo.moe/llms.txt
> Use this file to discover all available pages before exploring further.

# Libraries

> Reusable YAML functions.

Libraries let scripts reuse action lists as functions. By default, place YAML
files in `configs/Mikting/libs/`. Set `libs.dir` to use another location and
set `allowSubfolders: true` to load nested files.

A library file declares `version: 1` and a list of functions. This example adds
two numbers and leaves the result in `result`:

```yaml theme={null}
version: 1
functions:
  - name: math.add
    params: [a, b]
    actions:
      - id: miktingMath
        args: { expr: '[[a]] + [[b]]', storeAs: result }
```

Files without `version: 1` are skipped with a warning. Call a function with
`miktingCallFunction`:

```yaml theme={null}
- id: miktingCallFunction
  triggers: messageCreate
  args:
    name: math.add
    args: { a: 2, b: 3 }
    storeAs: sum
    follow-up-actions:
      - id: miktingReply
        args: { content: '2+3=[[sum]]' }
```

The function receives the parent variables and the supplied parameters. Its
parameter scope is isolated from the caller. Only `result` is copied back,
using the `storeAs` name when supplied. Other variables created by the function
stay in its scope.

`miktingInclude { path }` serves a different purpose: it runs an
`{actions:[...]}` snippet in the caller's shared scope. Include paths must stay
inside the bot working directory.

On first load, Mikting creates the default library directory and copies the
bundled `math.yml`, `strings.yml`, and `store.yml` examples from
`resources/libs/`. Existing directories and edited files are preserved. Add or
change a YAML file, then run `/reload` to load it. `/mikting-libs` lists
function names and parameters.

## Move libraries from the old location

If an existing install uses `scripting/libs/mikting/`, move those files to
`configs/Mikting/libs/` and set:

```yaml theme={null}
libs:
  dir: configs/Mikting/libs
  allowSubfolders: true
```

Run `/reload` after changing the path. Updating the addon keeps the configured
`libs.dir`; it does not move files for you.

[Documentation home](https://mikting.docs.komo.moe/index.md) · [Source Markdown](https://gitlab.com/komomori/mikting/-/blob/main/docs/mikting-libs.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.