|
| 1 | ++++ |
| 2 | +title = "Introduction" |
| 3 | +weight = 411 |
| 4 | +description = "Learn how to use buttons, modals, and select menus in custom commnads." |
| 5 | ++++ |
| 6 | + |
| 7 | +{{< callout context="danger" title="Danger: Advanced Topic" icon="outline/alert-octagon" >}} |
| 8 | + |
| 9 | +Use of interactions within YAGPDB is an advanced topic; you will need a thorough understanding of YAGPDB's scripting |
| 10 | +language before learning interactions. |
| 11 | + |
| 12 | +{{< /callout >}} |
| 13 | + |
| 14 | +Interactions within Discord allow server members to use alternative, built-in features to trigger bots to take action |
| 15 | +other than messages or reactions. These features include builtin buttons, dropdown selection menus, or submitting a |
| 16 | +modal (basically a pop-up form). Within custom commands it is possible to not only create and customize these new |
| 17 | +interactive features, but respond to them as well, opening up new possibilities for ephemeral message responses, modals, |
| 18 | +and more within custom commands. |
| 19 | + |
| 20 | +## Interaction Lifetime |
| 21 | + |
| 22 | +An interaction's lifetime starts with the initial *interaction* with an *interactive element*. |
| 23 | + |
| 24 | +1. A server member clicks on a *button*, uses a *menu*, or submits a *modal* after filling it out. |
| 25 | +2. This interaction is sent to YAGPDB, and becomes available to trigger any custom commands which match it. |
| 26 | +3. Within the triggered custom command(s), YAGPDB should then *respond* once to the interaction, sending a message, |
| 27 | + updating the triggering message, or sending a modal. This may only be done within the CC which was triggered by the |
| 28 | + interaction. |
| 29 | +4. (optional) Continue to send followup responses for up to 15 minutes until the interaction token expires. |
| 30 | + |
| 31 | +```mermaid |
| 32 | +graph LR; |
| 33 | +A[Button pressed] --> B{CC Triggered} |
| 34 | +C[Menu used] --> B |
| 35 | +D[Modal submitted] --> B |
| 36 | +B --> E[Bot sends message response] |
| 37 | +B --> G[Bot sends modal response] |
| 38 | +B --> H[Bot updates message] |
| 39 | +E -.-> F(Bot sends followups) |
| 40 | +G -.-> F |
| 41 | +H -.-> F |
| 42 | +``` |
| 43 | + |
| 44 | +## Definitions |
| 45 | + |
| 46 | +On the following pages, we will the listed terms with their respective definitions, which are also used by the Discord |
| 47 | +API. |
| 48 | + |
| 49 | +Interaction |
| 50 | +: A user engaging with YAGPDB through one of Discord's builtin features: Clicking a button, Making a |
| 51 | +selection with a select menu, or Submitting a modal. |
| 52 | + |
| 53 | +Response |
| 54 | +: YAGPDB is required to respond promptly after receiving an interaction by either sending a message or modal, or by |
| 55 | +updating the message on which the interaction was triggered. If it does not do this, the user triggering the interaction |
| 56 | +will see a "This application did not respond" error. The bot cannot respond to an interaction more than once. |
| 57 | + |
| 58 | +Followup |
| 59 | +: Since YAGPDB may only *respond* to an *interaction* once, it is subsequently required to send an interaction |
| 60 | +followup if it still needs to interface with the interaction. These followups can be sent up to 15 minutes after the initial |
| 61 | +interaction, and you can send as many as you want. YAGPDB may only send a followup in one of the following ways: Sending |
| 62 | +a followup message, editing an initial response or previous followup message, or getting an initial response or previous |
| 63 | +followup message. |
| 64 | + |
| 65 | +Interactive Elements |
| 66 | +: Elements users can interact with to send *interactions*, i.e. buttons, menus, and modals. |
| 67 | + |
| 68 | +Message Components |
| 69 | +: *Interactive Elements* which can be attached to YAGPDB's Discord messages, i.e. buttons and menus. |
| 70 | + |
| 71 | +Button |
| 72 | +: A button appearing in or under a Discord message sent by YAGPDB. You can create and customize these |
| 73 | +buttons' appearance and behavior with color, emoji, label text, etc. When a button is clicked, an *interaction* is sent |
| 74 | +to the bot. |
| 75 | + |
| 76 | +Menu |
| 77 | +: A dropdown select menu appearing in or under a Discord message sent by YAGPDB. You can create and customize these |
| 78 | +menus' appearance and behavior with placeholder text, predefined options with labels, descriptions, and/or emojis, |
| 79 | +designate the entire menu as a user or role select menu instead, etc. When a select menu is used, an *interaction* is |
| 80 | +sent to the bot. |
| 81 | + |
| 82 | +Modal |
| 83 | +: A pop-up form YAGPDB can send in response to an interaction. It allows users to privately input text which |
| 84 | +is sent directly to YAGPDB for use in CC scripting. You can create and customize these modals' appearance and |
| 85 | +behavior with a title and fields. YAGPDB can both **receive a submitted modal** (which is an |
| 86 | +*interaction*), and **send a modal** for a member to fill out, (which is an interaction *response*). |
| 87 | + |
| 88 | +Ephemeral |
| 89 | +: An ephemeral message is sent to a server channel but only appears to a single user. YAGPDB cannot send |
| 90 | +these ephemeral messages to users except in response to an *interaction*. Both *response* messages and *followup* |
| 91 | +messages can be ephemeral. |
0 commit comments