|
1 | 1 | --- |
2 | 2 | id: args |
| 3 | +sidebar_label: "$(args)" |
| 4 | +description: "Learn how to use the $(args) variable in StreamElements chatbot commands for dynamic, user-input-based responses." |
3 | 5 | tags: |
4 | 6 | - chatbot |
5 | 7 | - variable |
6 | 8 | keywords: |
7 | 9 | - args |
8 | 10 | - arguments |
| 11 | + - chatbot commands |
| 12 | + - user input |
| 13 | + - dynamic responses |
9 | 14 | --- |
10 | 15 |
|
11 | | -# $(args) |
| 16 | +# $(args) Variable |
| 17 | + |
| 18 | +## Overview |
12 | 19 |
|
13 | 20 | The `$(args)` variable is a powerful feature in StreamElements chatbot commands that allows you to access and manipulate arguments passed by users. This enables dynamic responses based on user input, enhancing the interactivity of your chatbot. |
14 | 21 |
|
15 | | -## Basic Usage |
| 22 | +## Usage |
16 | 23 |
|
17 | | -### Syntax |
| 24 | +The basic syntax for using the `$(args)` variable is: |
18 | 25 |
|
19 | 26 | ``` |
20 | 27 | $(args) |
21 | 28 | ``` |
22 | 29 |
|
23 | | -### Description |
| 30 | +You can access specific arguments using numeric indices, starting from 1: |
24 | 31 |
|
25 | | -The `$(args)` variable represents all arguments passed to a command. You can access specific arguments using numeric indices, starting from 1. |
| 32 | +``` |
| 33 | +$(1), $(2), $(3), etc. |
| 34 | +``` |
26 | 35 |
|
27 | | -### Examples |
| 36 | +## Examples |
28 | 37 |
|
29 | | -1. Accessing the first argument: |
| 38 | +1. Greeting a user: |
30 | 39 | ``` |
31 | 40 | Command: !greet $(1) |
32 | 41 | User input: !greet World |
33 | 42 | Output: Hello, World! |
34 | 43 | ``` |
35 | 44 |
|
36 | | -2. Using multiple arguments: |
| 45 | +2. Introducing a user: |
37 | 46 | ``` |
38 | 47 | Command: !introduce $(1) is $(2) years old |
39 | 48 | User input: !introduce Alice 25 |
40 | 49 | Output: Alice is 25 years old |
41 | 50 | ``` |
42 | 51 |
|
43 | | -## Advanced Features |
44 | | - |
45 | | -### $(args.emote) |
46 | | - |
47 | | -This variant outputs an argument only if it is a valid emote. |
48 | | - |
49 | | -#### Syntax |
50 | | - |
51 | | -``` |
52 | | -$(n.emote) |
53 | | -``` |
54 | | -Where `n` is the argument index. |
55 | | - |
56 | | -#### Example |
| 52 | +## Parameters |
57 | 53 |
|
58 | | -``` |
59 | | -Command: !emote $(1.emote) |
60 | | -User input: !emote Kappa |
61 | | -Output: Kappa |
| 54 | +The `$(args)` variable has two special variants: |
62 | 55 |
|
63 | | -User input: !emote Hello |
64 | | -Output: [No output, as "Hello" is not an emote] |
65 | | -``` |
| 56 | +1. `$(n.emote)`: Outputs an argument only if it is a valid emote. |
| 57 | + ``` |
| 58 | + Command: !emote $(1.emote) |
| 59 | + User input: !emote Kappa |
| 60 | + Output: Kappa |
| 61 | + ``` |
66 | 62 |
|
67 | | -### $(args.word) |
| 63 | +2. `$(n.word)`: Outputs an argument only if it does not contain symbols. |
| 64 | + ``` |
| 65 | + Command: !word $(1.word) |
| 66 | + User input: !word Hello |
| 67 | + Output: Hello |
| 68 | + ``` |
68 | 69 |
|
69 | | -This variant outputs an argument only if it does not contain symbols. |
| 70 | +Where `n` is the argument index in both cases. |
70 | 71 |
|
71 | | -#### Syntax |
| 72 | +## Related Variables |
72 | 73 |
|
73 | | -``` |
74 | | -$(n.word) |
75 | | -``` |
76 | | -Where `n` is the argument index. |
| 74 | +- [$(user)](user): Represents the username of the person using the command |
| 75 | +- [$(channel)](channel): Represents the channel name where the command is used |
77 | 76 |
|
78 | | -#### Example |
| 77 | +## FAQ |
79 | 78 |
|
80 | | -``` |
81 | | -Command: !word $(1.word) |
82 | | -User input: !word Hello |
83 | | -Output: Hello |
| 79 | +**Q: What happens if I try to access an argument that wasn't provided?** |
84 | 80 |
|
85 | | -User input: !word Hello! |
86 | | -Output: [No output, as "Hello!" contains a symbol] |
87 | | -``` |
| 81 | +A: If you try to access an argument that wasn't provided (e.g., `$(2)` when only one argument was given), the output will be blank. |
0 commit comments