This is a small introduction to what slash commands are and how they are going to be used in NabBot. This article might be a bit technical, but I will do my best to keep things simple.
Note: All information and images displayed here is still under development from both Discord and NabBot.
In the beginning of Discord, bots weren't official. Initially bots were just regular Discord users being controlled by scripts. You could add them to friends, you couldn't just add them to a server, the bots had to use invite links.
It wasn't until December 2015 that the first "unofficial" API was released by Discord and the bots we know now were introduced, with their BOT badge and tools to add them to servers in a secure way.
Commands were the core functionality of the majority of bots. You would put a special "prefix" (unique combination of symbols), the name of the command and maybe some arguments, and the bot would respond to it.
This works by having bots literally read every single message they see, trying to see if it starts with the prefix they set, and then checking if it matches with any command registered.
Prefixes would let you avoid collisions between bots, for example, if NabBot has $
as a prefix. Using $about
would only trigger a response from NabBot (as long as there are no other bots in the server with the same prefix).
Commands can have arguments, and they were also written into the message. Let's take at the $share
command:
When you use $share 135
, NabBot checks the incoming message and turns it into the following:
$ |
Command Prefix |
share |
Command Name |
135 |
Command Arguments |
And now NabBot knows it has to call the function for the share
command with the argument 135
and give you the response.
Since the only way to call commands is using messages, in order to have multiple arguments, you would have to get creative with the way they are read, usually using commas or spaces to separate them. This leads to some complicated commands:
$imbuement powerful void, 2.7k, 4k, 2.4k, 38k
:powerful void
2.7k
4k
2.4k
38k
How would you know the available parameters and how to use it? You need to either use $help imbuement
, go to the documentation. And even then, you would be greeted by this: «name»[,price1[,price2[,price3]]][,tokenprice]
. A complicated syntax describing which are optional, and which are required arguments. But there is only so much you can do when you only have text to communicate.
In a way, commands have never been an official feature of Discord, they have always been a "developer hack"
As mentioned before, in order for bots to detect commands, they have to read every single message they can see. Bots will usually just ignore everything that is not a command, but there have been cases of malicious bots that store every single message they read, creating databases of user messages and collecting private information.
This is one of the points Slash Commands are addressing. After April 2022, bots in over 75 Discord servers won't be able to see the content of messages, unless they are verified and request access to the Discord team for them.
Slash commands are a completely different approach to commands. Developers are able to register to Discord a list of all their commands, along with descriptions, argument names, argument descriptions, argument types, etcetera. Discord receives this and stores the commands in order to display them to users when they type /
(slash).
When you type /
, you will see a list of Discord's built-in commands (/giphy
, /tableflip
, etc), and you will see the available commands of bot in the server:
From here, you can already scroll through the list of commands and see a description for them and their parameters, without having to use a help
command or check documentation.
If you already know the command, you can just keep typing the command and the list will start narrowing down.
One of the main advantages of slash commands is that all arguments are visible to the user right from Discord. Let's try the imbuement command we talked about.
At this point, you can already see a description of the command, that it has a required name
argument and 4 optional arguments.
If we add a space, it will switch to filling out the name
argument, showing us a description or explanation of the command. Also, if we put our mouse over the +4 optional
legend, it will show the list of arguments.
Once we have started typing the name, we will see a prompt indicating to press the TAB
key to finish. The list of optional arguments will appear, along with their descriptions.
At this point, we can already press ENTER
to finish, since we are already done filling all the required arguments.
In order to fill the optional arguments, we can:
TAB
to move focus to the options list and use the arrow keys or mouse to select the desired option.TAB
twice, to automatically select the first option on the list.TAB
or ENTER
when you narrowed it down to a single option, or finish typing it with :
(e.g. price_first:
).If we typed an incorrect value, the option would turn red and shows us what is wrong:
This way, we would only be able to send the command once everything is correct, instead of having to try repeatedly until we get it right.
Once we are done filling all the desired values, they will show up like this:
In this point, you can still edit any argument by clicking on it and modifying the value. If you are done, you can hit enter and the command will be sent.
Unlike regular commands, you won't be actually sending a message, so the chat will only display the command's response, instead of having two messages there.
NabBot would simply receive a request for the command, already containing all the necessary information: which command was used, the values for each argument, so no second guessing is necessary.
Let's take a look at another command with complicated arguments: $distanceskill
. To use it you have to type something like:
$distanceskill 56 3 70 rp 10
56
3
70
rp
10
Trying to remember the order of the parameters can be hard. Meanwhile, with slash commands, this is what you would see:
And same as with the imbuement
command, you would see descriptions for every argument as you go.
Another feature of Slash Commands is that you can define options for an argument, so when trying to fill the vocation
argument, you would be presented with a list of available options, so you will always get it right.
Slash commands also let you define special argument types such as channels, roles or users.
If you have used Autoroles, you might have run into the following issue with the $autorole add
. If you are trying to create an autorole rule for a role that has spaces, you have to use quotes around them. This is explained in the command's documentation, but again, you have to dig for the information. Alternatively, you can just mention the role, instead of using quotes. But this will mean every member with that role will be notified, which is something we don't want.
With slash commands, you are already presented with a list of roles, and you can type the name of the role to filter it out:
Another example is the $levels user
command. To specify the user you have 3 options:
$levels user Sam
: Type the name of the user. If multiple users have the same name, it is impossible to specify which one, and the bot will pick the first one it finds.$levels user @Sam
: Mention the user, since we get autocompletion when we type @
, you will be able to select the specific user you want. However, the user will receive a notification from you.$levels user 254301278946066432
: Use the ID of the user. However, not everyone knows how to get the ID easily, but this is a way to ensure you select the correct user and not notify them.With Slash Commands, you will always have a list of users displayed, and you can type the name of the user to narrow it down:
The selected user would not receive a mention notification.
Another possibility with Slash Commands is that you can send messages that will only be visible to the person that used the command.
This way, commands that show personal information (like your list of reminders), or that modify server settings can be hidden, and they will not fill the channel for others.
While it would be possible to make all commands "private", we believe sometimes you want to show others the result of a command like share
, splitloot
or item
, so these commands will remain visible to all.
In the image above, the first message is only visible to the user, while the second message is visible to everyone.
Slash commands definitely have great potential and really help in making everything "What you see is what you get".
However, as mentioned before, Slash Commands are a feature still in development, so we are still missing some features:
splitloot
, event add
(descriptions).loot
.$monster
, $mob
, $creature
. This won't be supported.Other interesting features that are planned for the future or already in the making:
Join our Discord server and tell us what you think of these changes!