# advanced ii: using user arguments

## ✎ utilising user input

* the more you use autoresponders, the more complicated your ideas will get. by using the user's arguments, you'll be able to allow users to provide context.
* follow up to learning match modes from [advanced i](https://docs.mimu.bot/autoresponder/guide/advanced-i-different-matchmodes), if your match mode is not `exact`, (i.e. it is `startswith`, `endswith`, or `includes`), you will be able to use your arguments as a part of your response via the `[$N]` variable.&#x20;
* this allows you to create commands where there are "user target" or for mimu to respond with the user's input.

{% hint style="info" %}
the `$` sign has **nothing to do with money or currency**. it is simply the symbol developers decided to use for reference of arguments!\
\
the `N` letter refers to **any number**. you do not *literally* put `[$N]` in your response, you should put `[$1]`, `[$2]`, `[$3]`...
{% endhint %}

#### i'm still confused on why i would need this

* let's take a simple `!kiss` command. you've changed it so the match mode is `startswith` so that mimu responds, like below:

`/autoresponder add trigger:!kiss reply:awwh, how cute, you kissed them!`

`/autoresponder editmatchmode trigger:!kiss matchmode:startswith`

![without arguments](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWV9HSoyYY2fyfAZlSL%2F-MWVATXLmOmPFcVOE402%2Fimage.png?alt=media\&token=2633f81f-2b4f-40eb-a207-5b85b614d4fb)

![the "startswith" matchmode also responds with text after the trigger](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWVElnoJNlgvUhrhszM%2F-MWVF1ZzZE8F4gv3zMAq%2Fimage.png?alt=media\&token=b111bc98-e00b-4b33-a68c-444a4992588f)

* as you can see, regardless of what the text / user input is after the trigger, the response is always static.
* now, the problem is, wouldn't it be cool if it responded with "awwh, how cute, @iara kissed @pillowow" instead?
* this is why you might want to use user arguments:&#x20;

`/autoresponder editreply trigger:!kiss reply: awwh, how cute, {user} kissed [$1]!`

![using user arguments as a part of your response](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWVXHpQynLsvk5RwFVf%2F-MWVYr0rr6LJYR4yWbvf%2Fimage.png?alt=media\&token=f66b3adb-5272-4796-b0be-4f6233872d20)

## ✎ how do i use user arguments?

* in order to refer to the extra words *before or after* the autoresponder trigger (depending on the type of matchmode you have), you have to replace N with the number of the word you'd like to use as a placeholder in the response.
* for instance, `[$1]` would be the first word, `[$2]` would be the second word, `[$3]` would be the third word, and so on, so forth.
* you can also chain multiple words together using the `+` sign.
* for example, `[$1+]` would be the placeholder to show the first word and everything afterwards; and `[$2+]`would be the placeholder to show the second word and everything afterwards.
* you can also do a range of arguments, for example, `[$3-5]` would be equivalent to `[$3] [$4] [$5]` , which returns the 3rd, 4th and 5th words.

![a more visual example of what arguments are](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWVElnoJNlgvUhrhszM%2F-MWVGtTsoxDRj_T2JLyz%2Fimage.png?alt=media\&token=f6582139-2a65-45d9-8d05-2be0339827f6)

## ✎ exercise questions

let's do a quick exercise! you can jump to the [exercise answers](#exercise-answers) when you're done.

1. what's `[$1]` in the following ar?
   * creating the ar: `/autoresponder add trigger:welcome reply:let's welcome [$1]!`
   * editing matchmode: `/autoresponder editmatchmode trigger:welcome matchmode:startswith`
   * trigger: `welcome iara to the server!`
2. what's `[$2+]` in the following ar?
   * creating the ar: `/autoresponder add trigger:.bonk reply:you bonked [$1] with [$2+]!`
   * editing matchmode: `/autoresponder editmatchmode trigger:.bonk matchmode:startswith`
   * trigger: `.bonk iara a fish i found from the sea`
3. what's mimu's response to the following ar?
   * creating the ar: `/autoresponder add trigger:are cool reply:i see that you find [$1+] cool.`
   * editing matchmode: `/autoresponder editmatchmode trigger:are cool matchmode:endswith`
   * trigger: `hoodies without the hood are cool`
4. let's try something more abstract. what's mimu response to the following ar?
   * creating the ar: `/autoresponder add trigger:.guess reply:[$1] [$3-$5]`
   * editing the matchmode: `/autoresponder editmatchmode trigger:.guess matchmode:startswith`
   * trigger: `.guess abc def ghi jkl mno pqr`

## ✎ some practical examples

below we've given you some simple yet easy to understand examples for you to start with.

| commands                                                                                                                                                                                                           | example input + output                                                                                                                                         |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>/autoresponder add trigger:.cuddle reply:you cuddled \[$1+]!</code></p><p><code>/autoresponder editmatchmode trigger:.cuddle matchmode:startswith</code></p>                                              | <p>input: <code>.cuddle iara and mimu</code></p><p>response: <code>you cuddled iara and mimu!</code></p>                                                       |
| <p><code>/autoresponder add trigger:are cute reply:i see, you find \[$1+] cute!</code></p><p><code>/autoresponder editmatchmode trigger:are cute matchmode:endswith</code></p>                                     | <p>input: <code>japanese things are cute</code></p><p>output: <code>i see, you find japanese things cute!</code></p>                                           |
| <p><code>/autoresponder add trigger:.sleep reply:you made \[$1] sleep by \[$2+]</code></p><p><code>/autoresponder editmatchmode trigger:.sleep matchmode:startswith</code></p>                                     | <p>input: <code>.sleep iara throwing pillows</code></p><p>output: <code>you made iara sleep by throwing pillows</code></p>                                     |
| <p><code>/autoresponder add trigger:iara reply:{sendto:#logs} hey @iara, {user\_name} mentioned your name in {channel}!</code></p><p><code>/autoresponder editmatchmode trigger:iara matchmode:includes</code></p> | <p>input: </p><p><code>lol iara is stupid >-></code></p><p>output (in #logs):</p><p><code>hey @iara#0001, username mentioned your name in #channel!</code></p> |

{% hint style="info" %}
if you use `includes` with the `[$N]` placeholder for arguments, all arguments will be chained together. for example, if your trigger is `uwu` and you type `a b c uwu d e`, then `[$1] = a, [$2] = b, [$3] = c, [$4] = d, [$5] = e`, and `[$1+] = a b c d e`.
{% endhint %}

## ✎ using user arguments in user placeholders

* in order to convert user placeholders to a "targeted" user (a user outside of that invoked), you can convert [user placeholders found in the variable list](https://docs.mimu.bot/resources/variables-placeholders-and-functions#user-author-information) to a function.
* here's a quick example:
  * typically, `{user_createdate}` returns the user's invoked create date.
  * however, if you did `{user_createdate:[$1]}` , it returns the first argument user's create date.
* this allows you to create information commands of **other users**. let's view a quick example here:

`/autoresponder add trigger:.membinfo reply:{requirearg:1|user} showing information of {user_tag:[$1]} . . .` \
`loading . . . !`\
`> - server nick : {user_nick:[$1]}`\
`> - joined serv : {user_joindate:[$1]}`\
`> - joined disc : {user_createdate:[$1]}`\
`> - server bal  : {user_balance:[$1]}`

`/autoresponder editmatchmode trigger:.membinfo matchmode:startswith`

<figure><img src="https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LjUSz3NQrpyR-tHhUV-%2Fuploads%2FiuOgnpLR6eVwUHO4cAFw%2FScreen%20Shot%202023-09-11%20at%2010.59.13%20PM.png?alt=media&#x26;token=ddf4d4c9-8a21-46b2-a051-cf4f9c8cbd0e" alt=""><figcaption></figcaption></figure>

* this is fantastic because this allows you to create commands and gain more information on other users other than the user invoked.

## ✎ using user arguments in functions

* as you may expect, you can also utilise these user argument placeholders in your functions, too!
* some functions allow you to take the action on another specified user via an optional argument.

let's view a quick example of a command that allows you to manually verify people to enter your server:

/`autoresponder add trigger:.verify reply:{requirerole: Mods} {addrole: @verified | [$1+]} {user} has verified [$1+] !`\
`/autoresponder editmatchmode trigger:.verify matchmode:startswith`

![](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWVNTM32lUKfGHlu2P4%2F-MWVRxBjBP8p94fDUNWT%2Fimage.png?alt=media\&token=99a3c4fb-09db-4a61-a240-e3c6d6ecd90d)

* in this example, we're using the `{addrole:}` function. as seen in the [documentation of the variable list](https://docs.mimu.bot/resources/variables-placeholders-and-functions#miscellaneous), this accepts an optional "user" input after the pipe |, i.e. `{addrole:[role]|<user>}`.
* hence, if someone with the role "Mods" runs `.verify @user`, `[$1+]` would be defined as the @user which would be filled in the function as `{addrole:@verified | @user}`.
* note that `[$1+]` allows verification of users with spaces in their username, *not* verification of multiple users at once, as it accepts user#tag inputs too.

{% hint style="info" %}
there are several functions that accept an optional "user" input! check out the [function list](https://docs.mimu.bot/resources/variables-placeholders-and-functions#function-list) for more information.
{% endhint %}

## ✎ requiring specific arguments to be specific type of input

* as you get more complex with using arguments, you may want the user to input specific types of data.
* by using the `{requirearg:}` function, you can make mimu tell the user they might have done something wrong if they provide invalid arguments.

### ♪ when will i need to use this?

* let's go back to the [kiss command we made earlier](#im-still-confused-on-why-i-would-need-this), but now we'll quickly add user inputs in, so we have this:

`/autoresponder editreply trigger:!kiss reply:awwh, how cute! {user} kissed [$1] !`

* however, users who didn't write this autoresponder might not know that they have to @mention the user they want to kiss (and hence they might just type `!kiss`  without other arguments.
* this means arguments will be missing as `[$1]` isn't defined by the user input.&#x20;
* by requiring arguments, you will prevent the user from sending incorrect data.

### ♪ how do i use this?

* the `{requirearg:}` variable accepts a number, with an optional type after the pipe | symbol.
* ex. you want to make the user define `[$1]` (i.e. the first argument), then you can put `{requirearg:1}` in your autoresponder response area.
* ex 2. if you'd like to make the user define `[$1]` (i.e. the first argument) but it **has to be a user**, then you can put `{requirearg:1|user}` in your autoresponder response area.
* this also extends for other types. the current supported types are `user`, `channel`, `color`, `role` and `number`.

let's view an example.

`/autoresponder add trigger:!cuddle reply:{requirearg:1|user} {user} cuddled [$1] c:`\
`/autoresponder editmatchmode trigger:!cuddle matchmode:startswith`

![output when the user doesn't put in the right arguments!](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWVNTM32lUKfGHlu2P4%2F-MWVPFrzQ0lMlXGbjl12%2Fimage.png?alt=media\&token=3f7933ff-58e3-4a4d-b3a6-a94c1cb6cd27)

![when the user puts in the right arguments](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWVNTM32lUKfGHlu2P4%2F-MWVPQYc3XyWl1WQ5RAA%2Fimage.png?alt=media\&token=d5fd6669-0ba7-4d0f-9894-3747bc209b1b)

{% hint style="info" %}
this allows you to create even more complex commands that modify other people's balances, for example; or create commands where you can specify colors for the embed, or otherwise. check out the [steal command example](https://docs.mimu.bot/resources/autoresponder-examples#steal-user-amount-command) and [embedsay command example](https://docs.mimu.bot/resources/autoresponder-examples#embedsay-color-text-command).
{% endhint %}

## ✎ exercise answers

1. iara
2. a fish i found from the sea
3. i see you find hoodies without the hood cool.
4. abc ghi jkl mno

## [⚠️](https://emojipedia.org/emoji/%E2%9A%A0%EF%B8%8F/) important reminder - READ!

* it is advised that if you're going to use arguments, you should try to require arguments and their types as much as possible, as mentioned in the [require specific arguments to be a specific type of input](#requiring-specific-arguments-to-be-specific-type-of-input) section.&#x20;
* this has better error messaging, which in turns allows the user to figure out what they did wrong.

![it's always better to tell the user what they did wrong.](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWYYP4s31SPmT6uT8qg%2F-MWYc0iBNV9Gh0OSD620%2Fimage.png?alt=media\&token=65a0f065-d1dc-4188-864b-21fb40547d92)

* it's also **strongly advised to embed your responses if you do not specify a specific type of input**. i.e. `{requirearg:1}` only, or no `{requirearg:}` function variable anywhere.
* this is because if a user inputs a role mention as their arguments, mimu **will respond with such arguments in the response** which may cause unwarranted role mentions **if you have given mimu the permission to ping any role regardless of the mention toggle or the ADMINISTRATOR permission, like this**:

![if you've decided to give Mimu this permission.](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWYcwQBPsXzPc8PFi1Q%2F-MWYd9mkQdCWyBMg0zvA%2Fimage.png?alt=media\&token=d90c5cd3-c305-48f7-9748-b26a5728cddc)

![OR this permission.](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWYcwQBPsXzPc8PFi1Q%2F-MWYdH04dIpqNUjscnhm%2Fimage.png?alt=media\&token=741c2e8e-5ba9-41cf-8044-c7ed331d9b74)

* this **prevents bad users in your server from cold-mentioning roles through these custom autoresponders** and hence safeguards your server !

![if the user decides to put roles in arguments, but you don't have any filtering](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWYYP4s31SPmT6uT8qg%2F-MWYcETUae6gB4fqjPLW%2Fimage.png?alt=media\&token=2a1536ba-2981-4f02-807b-0db04a2fb2af)

* since embeds have role mentions suppressed, this will prevent people from using your AR in a malicious way.

![use embeds to avoid people abusing your AR.](https://1355643618-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LjUSz3NQrpyR-tHhUV-%2F-MWYYP4s31SPmT6uT8qg%2F-MWYcbNvUcMlIiNx684d%2Fimage.png?alt=media\&token=e61ab82f-77cb-41e5-8bff-4f9f69c7fdac)
