Slash Command
Introduction
triggers when a user uses a slash command. This needs to be a slash command from the bot!
Creating a slash command
In this example we will create /avatar
command, that show user avatar on request
Steps
Go to dashboard, your server page, click on Slash Builder
Click
Create
Fill the slash name and description, remember this name, we will use it later
To add user option, to the slash, select from the option menu
Select the User option (make sure background is blue)
Fill the option name, description, remember this name, we will use it later
Click
Deploy Command/Save
Create a new custom command, select type to be
Slash Command
andTrigger
to beavatar
(the name from step 3)Set the code to be (will be explained in next section)
Code
$let[user_id;$getOption[user]]
$interactionReply[
{title:Avatar of $usertag[$user_id]}
{image:$userAvatar[$user_id]}
]
- go to your server and use the command as fellow:
Output
Code Explanation
Retrieving the option from user
When user use the command like in Step 10, we can retrieve the option through $getOption function:
$getOption[option name]
In our example option name
is user
from step 6
then the user id will be stored in user_id
using $let, this way we can recall it later in the code through $user_id
:
$let[user_id;$getOption[user]]
Sending Message
Next, to send a message with $interactionReply[message]
but here we will send an embed with title and image, using {title}, {image} Curl Message Format:
$interactionReply[
{title:Embed Title}
{image:Embed Image}
]
- In title we want to set it to: Avatar of Mido#1234
To get the usernameMido#1234
we will use $userTag[user id], to specifiy the user we will use$user_id
:
Avatar of $userTag[$user_id]
- In Image to retrieve the user image, we will use $userAvatar[user id]:
$userAvatar[$user_id]
Whole code:
$let[user_id;$getOption[user]]
$interactionReply[
{title:Avatar of $usertag[$user_id]}
{image:$userAvatar[$user_id]}
]
Example 2: Sending Private Message
Let's modify the previous code, to make him reply in private to user instead like this:
$interactionReply accept 2 inputs by default: message, ephemeral
in the previous example we only used the first message, and 2nd input was by default no
To send the message in private we have to set the 2nd input ephemeral
to yes
That's it, Save and test it out