> For the complete documentation index, see [llms.txt](https://miulien.gitbook.io/bot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://miulien.gitbook.io/bot/en/utilities/reply.md).

# Auto Replies (reply)

**Reply is much more than an automatic keyword responder.** Without editing bot code, you can create welcome/leave messages, scheduled announcements, conditional rules, custom text commands, emoji reactions, and even game-launching replies.

Run `/reply` or `m!reply` to open the setup panel. Choose **Add Rule**, select a trigger, and configure its response. A single rule can have multiple weighted responses and a configurable trigger probability.

### 🧩 Four trigger types

| Type             | Purpose                                                    |
| ---------------- | ---------------------------------------------------------- |
| 💬 Message       | Respond to message text, including conditional expressions |
| 👋 Member joins  | Welcome new members                                        |
| 🚪 Member leaves | Send departure messages                                    |
| ⏰ Scheduled      | Post announcements at specified times                      |

Message triggers support **Exact match**, **Partial match**, and **Condition**. Scheduled rules support **daily**, **selected weekdays**, **selected days of the month**, or **one specified date/time**. Examples: daily at 08:00 or Monday/Wednesday/Friday at 20:30. Schedules use **Taiwan time (UTC+8)** and can target a selected channel.

### ✨ Practical examples

#### 🧮 A calculator in chat

Combine a conditional trigger with `{isexpression}` to avoid reacting to ordinary chat. For example, let players type `!calc 1+2*3` and receive `7`.

Condition:

```
{and|{contains|{message}|!calc}|{isexpression|{after|{message}|!calc}}}
```

Reply:

```
{count|{args}}
```

This combines prefix detection with expression checking. More complex calculations can use number functions and error handlers.

#### 🔎 Find multiple keywords

`{contains|source|search}` performs case-insensitive matching. Combine `{and}`, `{or}`, and `{not}` to express multiple conditions.

Contains "apple":

```
{contains|{message}|apple}
```

Contains both "apple" and "banana":

```
{contains|{message}|{and|apple|banana}}
```

Contains either one:

```
{contains|{message}|{or|apple|banana}}
```

Does not contain "banana":

```
{contains|{message}|{not|banana}}
```

Nested example, mentioning apples or bananas but not anything rotten:

```
{contains|{message}|{and|{or|apple|banana}|{not|rotten}}}
```

For more conditions, place `{and}` or `{or}` outside the `{contains}` expression. To select different reply text based on a condition, use `{if|condition|true text|false text}`.

#### 🦜 Repeat a user's message: `{message}`

`{message}` contains the full message that triggered Reply. For a partial-match trigger like `parrot says`, use:

```
🦜 You said: {message}
```

If the user posts `parrot says hello`, the entire original message is inserted. Use `{args}` to include only the text **after the trigger**, such as `hello`.

#### 🪪 Author-specific easter eggs: `{message_user}`

`{message_user}` is the author's numeric Discord ID, not a name or mention, and only applies to message triggers. For an author-specific "pudding" rule:

```
{and|{message_user}=123456789012345678|{contains|{message}|pudding}}
```

Reply:

```
🍮 Special guest! This pudding is yours.
```

Replace the sample ID with a real one. Compare IDs using exact equality (`=`), not substring matching via `{contains}`.

Multiple keywords can be nested under the author check:

```
{and|{message_user}=123456789012345678|{contains|{message}|{or|pudding|watermelon}}}
```

#### 💬 Turn messages into custom commands

`{args}` returns the full argument text following the trigger. `{arg|1}` and `{arg|2}` extract individual arguments. With a partial-match trigger `!choose`, typing `!choose hotpot sushi` lets a reply read the two choices separately and use random, text, or condition templates.

#### 🎯 Weighted random choices: `{item}` + `{weight}`

`{item|common|rare|legendary}` selects with equal probability. To specify relative weights:

```
{item|{weight|common|8}|{weight|rare|2}}
```

This gives roughly **80% common** and **20% rare**. An item without `{weight}` defaults to weight 1. Dynamic weights can use `{count}` and `{get}`. A weight may be zero, but not **all** weights; place `{weight}` directly inside the `{item}` options.

This differs from the Reply panel's **multiple-response weights**. The panel chooses which *reply* to send; `{weight}` chooses an *option within one reply*. The same idea works with `{react}`.

#### 🎲 Reuse one roll consistently

Two independent calls to `{random}` can return different results. Use `{set}` and `{get}` to reuse a value throughout one reply:

```
{set|roll|{random|1|100}}🎲 Rolled {get|roll}! {if|{get|roll}>=80|Great success!|Keep trying}
```

Temporary values last for **this reply only**, not across messages.

#### 🔢 Number base conversion

`{base|number|source base|target base}` works with integer bases **2–36**.

```
{base|FF|16|10}
```

Result: `255`. More details are available in the built-in template syntax help.

#### 🔐 Base64 encoding and decoding

Encode text with `{base64|encode|Hello}` → `SGVsbG8=` and decode it with `{base64|decode|SGVsbG8=}` → `Hello`. Unicode text and nested variables are supported, for example `{base64|encode|{message}}`.

**Base64 is encoding, not encryption.** See the built-in help for syntax, limits, and error handling.

#### 🎉 React without posting a new message

Automatically react to a triggering message:

```
{react|{item|👍|🎉|👀}}
```

Combine it with ordinary text, conditions, and role checks. `{react}` works for **message triggers only**, not member-join, member-leave, or time-based rules.

#### 🕒 Date/time and dynamic variables

`{time}` and `{date}` use Taiwan time by default. Specify a UTC offset such as `{time|9}` (UTC+9) or `{date|0}` (UTC). Usernames, server information, and random member variables provide more dynamic content.

#### 🎮 Launch games from replies

`{game|work}` opens the Work panel for the triggering member; it **does not perform work automatically**. `{game|pvz}` opens or resumes PvZ without advancing a turn. The new **`{game|wheel}`** opens an idle wheel; **the player must press Spin to draw a prize**.

Supported games: `slot`, `wheel`, `waterfire`, `snake`, `skating`, `garden`, `2048`, `work`, `rps`, and `pvz`. Use `{item}` or `{weight}` to select games randomly.

`{game}` works with message triggers only, opens **at most one game** per reply, and obeys each game's rules. Wheel accepts no extra parameters. See [Wheel](/bot/en/economy-games/wheel.md) for gameplay.

### 🛠️ Managing rules

* **Edit rules/responses** without recreating them.
* **Enable/disable rules** without deleting them.
* **Channel filters:** All channels, allowlisted channels, or excluded channels for message rules; selected output channels for join/leave/scheduled rules.
* **Reorder** rules and responses; order can affect which otherwise equal-priority rule wins.
* **Search and pagination** for large configurations.
* **Weights and trigger probabilities** for responses and message triggers.

Only **one rule** is selected for any given message even if multiple rules match. Valid native commands take precedence over auto replies.

### 📖 Finding the template syntax reference

Open `/reply` and select **📖 Template Syntax** for categorized explanations, a table of contents, pagination, and direct page navigation. Categories cover **users/roles, messages/arguments, servers/channels, dates/time, randomness, math, conditions, text operations, temporary variables, reactions, and games**.

### 📚 Template and variable index

Miulien currently has **62 function templates** and **26 general variable entries**, totaling **88 categorized entries**. View **📖 Template Syntax** in the bot for exact parameters and full documentation.

#### Function templates (62)

**Conditions and logic (8)**

`{if}`, `{and}`, `{or}`, `{not}`, `{contains}`, `{iferror}`, `{isnumber}`, `{isexpression}`

**Random and temporary storage (6)**

`{item}`, `{weight}`, `{random}`, `{arg}`, `{set}`, `{get}`

**Discord and games (7)**

`{mention}`, `{react}`, `{game}`, `{role}`, `{hasrole}`, `{rolecount}`, `{jackpot}`

**Date and formatting (6)**

`{time}`, `{date}`, `{quote}`, `{code}`, `{codeblock}`, `{spoiler}`

**Math and number bases (21)**

`{count}`, `{base}`, `{round}`, `{floor}`, `{ceil}`, `{fraction}`, `{mod}`, `{min}`, `{max}`, `{abs}`, `{clamp}`, `{sin}`, `{cos}`, `{tan}`, `{asin}`, `{acos}`, `{atan}`, `{rad}`, `{deg}`, `{log}`, `{number}`

**Text and encoding (14)**

`{base64}`, `{len}`, `{replace}`, `{escape}`, `{trim}`, `{upper}`, `{lower}`, `{capitalize}`, `{proper}`, `{left}`, `{right}`, `{slice}`, `{before}`, `{after}`

`{weight}` is an auxiliary template for `{item}` and cannot be used on its own.

#### General variables (26)

**Users and members (11)**

`{user}`, `{username}`, `{display_name}`, `{global_name}`, `{user_id}`, `{status}`, `{activity}`, `{random_online_member}`, `{random_member}`, `{random_member_a}`, `{random_member_b}`

**Server and channel (7)**

`{server}`, `{server_id}`, `{channel}`, `{channel_name}`, `{member_count}`, `{server_count}`, `{online_count}`

**Messages and special entries (8)**

`{message}`, `{message_user}`, `{args}`, `{br}`, `{nbsp}`, `{jackpot}`, `{time}`, `{date}`

`{time}`, `{date}`, and `{jackpot}` appear in both sections, so the **88 categorized entries correspond to 85 unique names**.

### 🔐 Permissions and rate limits

* Managing Reply requires **Manage Messages** or a role authorized via Miulien `permissions`.
* Message-triggered replies are limited to **one per second per channel** and **five per five seconds per user**. Excess triggers are skipped, not queued.
* Discord's **2,000-character message limit** applies. Reactions require the necessary bot permissions.

> Start with a simple partial-match text reply, then experiment with `{arg}`, `{item}`, `{weight}`, and `{react}` before exploring advanced conditional templates.
