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

# Build Custom Discord Slash Commands in erlc.dev Studio

> Create Discord slash commands that display server info, moderate members, and interact with your ERLC server using erlc.dev Studio automations.

Slash commands turn your Discord bot into an interactive control panel for your ERLC server. Instead of digging through spreadsheets or asking staff manually, your community can type `/serverinfo` and instantly see live player counts, join keys, and server names — all powered by erlc.dev Studio automations running behind the scenes.

<Note>
  Slash commands must be registered in the Discord Developer Portal or through the Studio bot setup page before they can trigger automations. Go to **Settings → Bot → Slash Commands** in Studio to register your commands, or add them manually in the [Discord Developer Portal](https://discord.com/developers/applications).
</Note>

***

## Part 1: `/serverinfo` — live server stats

This command lets anyone in your Discord server query live ERLC data on demand: the server name, current and max player counts, and the join key.

<Steps>
  <Step title="Add the slash command trigger">
    Drag an **`erlc_when_slash_command`** block onto the canvas. Set its **COMMAND** field to **`serverinfo`**. This block fires whenever a Discord member runs `/serverinfo` in any channel your bot can see.
  </Step>

  <Step title="Read server data">
    Attach four **`erlc_server_value`** blocks in sequence to read the fields you need:

    * **`Name`** — the ERLC server name.
    * **`CurrentPlayers`** — how many players are online right now.
    * **`MaxPlayers`** — the server's player cap.
    * **`JoinKey`** — the private code players need to join.

    You'll wire each of these into the `erlc_join_values` chain in the next step.
  </Step>

  <Step title="Build the response string">
    Use nested **`erlc_join_values`** blocks to concatenate all the data into a single readable message. A clear format looks like:

    ```
    "📡 Server: " + Name + "\n👥 Players: " + CurrentPlayers + "/" + MaxPlayers + "\n🔑 Join Key: " + JoinKey
    ```

    Each `erlc_join_values` block joins exactly two values (A and B), so nest them to chain more than two pieces of text together.
  </Step>

  <Step title="Reply to the interaction">
    Attach an **`erlc_bot_interaction_reply`** block and wire your completed `erlc_join_values` chain into its **MESSAGE** input. This sends the response as a reply to the slash command interaction, visible only to the invoker by default.
  </Step>
</Steps>

### `/serverinfo` block JSON

Paste this into **File → Import Blocks** to load the complete automation.

```json theme={null}
{
  "format": "erlc-studio-blocks",
  "version": 1,
  "workspace": {
    "blocks": {
      "languageVersion": 0,
      "blocks": [
        {
          "type": "erlc_when_slash_command",
          "id": "event_slash_1",
          "x": 48,
          "y": 48,
          "fields": {
            "COMMAND": "serverinfo"
          },
          "next": {
            "block": {
              "type": "erlc_bot_interaction_reply",
              "id": "action_reply_1",
              "inputs": {
                "MESSAGE": {
                  "block": {
                    "type": "erlc_join_values",
                    "id": "val_join_1",
                    "inputs": {
                      "A": {
                        "block": {
                          "type": "erlc_join_values",
                          "id": "val_join_2",
                          "inputs": {
                            "A": {
                              "block": {
                                "type": "erlc_join_values",
                                "id": "val_join_3",
                                "inputs": {
                                  "A": {
                                    "block": {
                                      "type": "erlc_join_values",
                                      "id": "val_join_4",
                                      "inputs": {
                                        "A": {
                                          "block": {
                                            "type": "erlc_join_values",
                                            "id": "val_join_5",
                                            "inputs": {
                                              "A": {
                                                "block": {
                                                  "type": "erlc_join_values",
                                                  "id": "val_join_6",
                                                  "inputs": {
                                                    "A": {
                                                      "block": {
                                                        "type": "erlc_text_value",
                                                        "id": "val_label_name",
                                                        "fields": {
                                                          "VALUE": "📡 Server: "
                                                        }
                                                      }
                                                    },
                                                    "B": {
                                                      "block": {
                                                        "type": "erlc_server_value",
                                                        "id": "val_server_name",
                                                        "fields": {
                                                          "FIELD": "Name"
                                                        }
                                                      }
                                                    }
                                                  }
                                                }
                                              },
                                              "B": {
                                                "block": {
                                                  "type": "erlc_text_value",
                                                  "id": "val_newline_1",
                                                  "fields": {
                                                    "VALUE": "\n👥 Players: "
                                                  }
                                                }
                                              }
                                            }
                                          }
                                        },
                                        "B": {
                                          "block": {
                                            "type": "erlc_server_value",
                                            "id": "val_current_players",
                                            "fields": {
                                              "FIELD": "CurrentPlayers"
                                            }
                                          }
                                        }
                                      }
                                    }
                                  },
                                  "B": {
                                    "block": {
                                      "type": "erlc_text_value",
                                      "id": "val_slash",
                                      "fields": {
                                        "VALUE": "/"
                                      }
                                    }
                                  }
                                }
                              }
                            },
                            "B": {
                              "block": {
                                "type": "erlc_server_value",
                                "id": "val_max_players",
                                "fields": {
                                  "FIELD": "MaxPlayers"
                                }
                              }
                            }
                          }
                        }
                      },
                      "B": {
                        "block": {
                          "type": "erlc_join_values",
                          "id": "val_join_7",
                          "inputs": {
                            "A": {
                              "block": {
                                "type": "erlc_text_value",
                                "id": "val_newline_2",
                                "fields": {
                                  "VALUE": "\n🔑 Join Key: "
                                }
                              }
                            },
                            "B": {
                              "block": {
                                "type": "erlc_server_value",
                                "id": "val_join_key",
                                "fields": {
                                  "FIELD": "JoinKey"
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}
```

<Tip>
  The join key is sensitive — consider restricting the `/serverinfo` command to staff-only channels or adding a permission check (see Part 2) so only authorized members can retrieve it.
</Tip>

***

## Part 2: `/kick` — permission-gated moderation command

This command lets staff members kick a Discord user directly from a slash command, with a built-in permission check to prevent abuse.

<Steps>
  <Step title="Add the slash command trigger">
    Drag an **`erlc_when_slash_command`** block onto the canvas and set **COMMAND** to **`kick`**. Connect a user argument option in the **OPTIONS** slot so Discord prompts the invoker to select a target member.
  </Step>

  <Step title="Check invoker permissions">
    Attach an **`erlc_discord_member_has_permission`** block. Set the **PERMISSION** field to either **`kick_members`** or **`administrator`**. This block returns true if the member who ran the command holds that permission in your server.
  </Step>

  <Step title="Branch on the permission result">
    Attach an **`erlc_if_else`** block and wire the `erlc_discord_member_has_permission` output into its **CONDITION** input.

    **THEN branch (has permission):**

    1. Attach an **`erlc_bot_kick`** block. Wire the target member's ID from the slash command option into the **USER\_ID** input.
    2. Attach an **`erlc_bot_interaction_reply`** block with a confirmation message, e.g. `"✅ Member has been kicked."`.

    **ELSE branch (no permission):**

    1. Attach an **`erlc_bot_interaction_reply`** block with a denial message, e.g. `"🚫 You don't have permission to use this command."`.
  </Step>
</Steps>

<Warning>
  Your bot must have the **Kick Members** permission in Discord and must be ranked above the target member in the server's role hierarchy. Attempting to kick someone with a higher or equal role will fail.
</Warning>

***

## Slash command overview

| Command | Trigger field | Key blocks used |
| - | - | - |
| `/serverinfo` | `serverinfo` | `erlc_server_value`, `erlc_join_values`, `erlc_bot_interaction_reply` |
| `/kick` | `kick` | `erlc_discord_member_has_permission`, `erlc_if_else`, `erlc_bot_kick`, `erlc_bot_interaction_reply` |

<CardGroup cols={2}>
  <Card title="Welcome Bot" icon="hand-wave" href="/guides/welcome-bot">
    Greet new members and assign roles automatically on join.
  </Card>

  <Card title="Moderation Automation" icon="shield-halved" href="/guides/moderation-automation">
    Auto-timeout high-wanted players and log mod actions.
  </Card>
</CardGroup>


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