> ## 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.

# Discord Event Triggers: Slash Commands, Buttons, and More

> Trigger automations from Discord interactions including slash commands, button clicks, modal submissions, select menus, and raw Discord gateway events.

Discord event triggers connect your Studio automations directly to your bot's interaction pipeline. Whether a user types a slash command, clicks a button in a bot message, submits a modal form, or simply joins your server, Studio can catch the event and execute your logic automatically. This page documents every Discord trigger block, its configuration fields, and the data fields you can read from each event.

## Trigger Blocks

<CardGroup cols={2}>
  <Card title="erlc_when_discord_event" icon="discord">
    Fires on raw Discord gateway events. Choose from messages, member changes, role/channel lifecycle events, reactions, voice state updates, and AutoMod actions.
  </Card>

  <Card title="erlc_when_slash_command" icon="slash">
    Fires when a user invokes a specific slash command your bot exposes. Supports option definitions via the SlashOptionsField.
  </Card>

  <Card title="erlc_when_discord_button" icon="hand-pointer">
    Fires when a user clicks a button component in any bot message. Matched by the button's custom ID.
  </Card>

  <Card title="erlc_when_discord_modal" icon="window-maximize">
    Fires when a user submits a modal (pop-up form). Matched by the modal's custom ID.
  </Card>

  <Card title="erlc_when_discord_select" icon="list">
    Fires when a user selects an option from a select menu component. Matched by the component's custom ID.
  </Card>
</CardGroup>

***

### `erlc_when_discord_event` — EVENT Values

<Accordion title="All EVENT options">
  | Value | When it fires |
  | - | - |
  | `discord_message_create` | A new message is sent in any channel the bot can see |
  | `discord_message_update` | An existing message is edited |
  | `discord_message_delete` | A message is deleted |
  | `discord_member_join` | A new member joins the Discord server |
  | `discord_member_remove` | A member leaves or is removed/banned |
  | `discord_channel_create` | A channel is created in the server |
  | `discord_channel_update` | A channel's settings are changed |
  | `discord_channel_delete` | A channel is deleted |
  | `discord_role_create` | A new role is created |
  | `discord_role_update` | An existing role is modified |
  | `discord_role_delete` | A role is deleted |
  | `discord_reaction_add` | A user reacts to a message |
  | `discord_reaction_remove` | A user removes their reaction |
  | `discord_voice_state_update` | A member joins, leaves, or moves between voice channels |
  | `discord_automod_action` | Discord's AutoMod blocks or flags a message |
</Accordion>

### `erlc_when_slash_command`

Set the **COMMAND** field to the exact slash command name (without the `/`) that should trigger this automation. Use the **OPTIONS** field (SlashOptionsField) to declare the options your command accepts — Studio passes each option's value into the event payload so you can read them with `erlc_discord_event_value`.

<Tip>
  Each unique slash command needs its own `erlc_when_slash_command` trigger block. You cannot use a wildcard here — keep your automations focused and easy to debug.
</Tip>

### `erlc_when_discord_button`

Set the **BUTTON\_ID** field to the custom ID you assigned to the button component when you created it. When a user clicks the button, Studio matches the ID and fires this automation. Always respond to button interactions promptly — Discord requires an acknowledgment within 3 seconds.

### `erlc_when_discord_modal`

Set the **CUSTOM\_ID** field to the custom ID of the modal you want to handle. The modal's submitted field values are available via `erlc_discord_event_value` using the `ModalValue`, `ModalValues`, and related fields.

### `erlc_when_discord_select`

Set the **CUSTOM\_ID** field to the custom ID of the select menu component. Use `SelectedValue` to read a single selection or `SelectedValues` for multi-select menus.

***

## Reading Discord Event Data

Use **`erlc_discord_event_value`** inside any Discord-triggered automation to extract data from the event payload. Select a field from the **FIELD** dropdown.

<Accordion title="All FIELD options for erlc_discord_event_value">
  | Field | Description |
  | - | - |
  | `DiscordUserId` | Snowflake ID of the user who triggered the event |
  | `DiscordUsername` | Username (handle) of the triggering user |
  | `DiscordMessage` | Full content of the message involved |
  | `DiscordMemberCount` | Current member count of the server |
  | `DiscordChannelId` | Snowflake ID of the channel the event occurred in |
  | `DiscordMessageId` | Snowflake ID of the message involved |
  | `DiscordRoleId` | Snowflake ID of the role involved (role events) |
  | `DiscordGuildId` | Snowflake ID of the Discord server |
  | `Command` | Name of the slash command that was invoked |
  | `ButtonId` | Custom ID of the button that was clicked |
  | `CustomId` | Custom ID of the modal or select menu component |
  | `SelectedValue` | The single selected option value from a select menu |
  | `SelectedValues` | Array of selected option values (multi-select menus) |
  | `ModalId` | Custom ID of the submitted modal |
  | `ModalFieldId` | The ID of a specific field within the modal |
  | `ModalValue` | Value of a single modal input field |
  | `ModalValues` | All submitted modal field values as a collection |
  | `ModalFileId` | ID of a file attachment submitted in a modal |
  | `ModalFileName` | File name of the attachment |
  | `ModalFileUrl` | URL to access the attachment |
  | `ModalFileSize` | Size of the attachment in bytes |
  | `ModalFileContentType` | MIME type of the attachment (e.g. `image/png`) |
  | `AutoModRuleId` | ID of the AutoMod rule that was triggered |
  | `MatchedKeyword` | The keyword that triggered the AutoMod action |
  | `MatchedContent` | The message content that matched the rule |
  | `EventType` | String name of the raw Discord event |
  | `Name` | Name associated with the entity involved (role, channel, etc.) |
  | `Emoji` | Emoji used in a reaction event |
</Accordion>

<Note>
  Not every field is populated for every event. For example, `Emoji` is only set for `discord_reaction_add` and `discord_reaction_remove` events. Reading an unpopulated field returns an empty string rather than an error.
</Note>

***

## Example Automation

The JSON below shows a slash command trigger that reads the invoked command name and sends a confirmation reply.

```json theme={null}
{
  "trigger": {
    "type": "erlc_when_slash_command",
    "fields": {
      "COMMAND": "status",
      "OPTIONS": []
    }
  },
  "actions": [
    {
      "type": "erlc_discord_event_value",
      "fields": {
        "FIELD": "Command"
      },
      "output_variable": "cmd_name"
    },
    {
      "type": "erlc_discord_event_value",
      "fields": {
        "FIELD": "DiscordUsername"
      },
      "output_variable": "invoking_user"
    },
    {
      "type": "erlc_bot_interaction_reply",
      "fields": {
        "MESSAGE": "✅ {{invoking_user}} ran /{{cmd_name}} — server is online!"
      }
    }
  ]
}
```

***

## Common Patterns

<Steps>
  <Step title="Pick the right trigger type">
    Use `erlc_when_slash_command` for intentional user commands, `erlc_when_discord_button` for guided menu flows, `erlc_when_discord_modal` for collecting structured input, and `erlc_when_discord_event` for passive monitoring like logging joins or AutoMod actions.
  </Step>

  <Step title="Set your custom IDs consistently">
    The BUTTON\_ID and CUSTOM\_ID fields must match the IDs you set when building message components. Use a naming convention like `btn_verify` or `modal_report` to stay organised.
  </Step>

  <Step title="Read the data you need">
    Attach `erlc_discord_event_value` blocks and select the fields your logic requires. Store each value in a named variable for use in downstream action blocks.
  </Step>

  <Step title="Respond to interactions">
    Discord interactions (slash commands, buttons, modals, selects) require a response within 3 seconds. Always place a reply or defer action block early in your automation to avoid interaction timeouts.
  </Step>
</Steps>

<Warning>
  If your automation does not acknowledge a slash command, button, modal, or select interaction within 3 seconds, Discord marks it as failed and shows an error to the user. Use a deferred response block if your logic takes time to complete.
</Warning>


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