Application Commands¶
Previously, commands were used by starting the message with a specific text (e.g. nb.
, or later @NabBot
), NabBot would recognize this and respond according to the called command. These are know as Chat Commands.
Chat Commands¶
Note
There are no chat commands in NabBot anymore, this section is only for comparison purposes.
Chat 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, checking if it starts with the prefix they set, and then checking if it matches with any command registered.
In April 2022, Discord restricted access to message content to bots, making bots unable to see the content of messages, unless it mentioned the bot specifically. This change made bots unable to process chat commands unless they were mentioned, making chat commands complicated to use. Discord released Slash Commands (later extended to Application Commands).
Slash Commands¶
Slash commands allow bots to register commands, making then visible to the user in their Discord client, letting them view the available commands, their descriptions and parameters. When the user types /
, a list of all the commands available is displayed.
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.
Command Arguments¶
One of the main advantages of slash commands is that all arguments are visible to the user right from Discord. Let's try the distance
(now named distance-skill
) command.
At this point, you can already see a description of the command, that it has 4 required arguments current_level
, percentage
, target_level
, vocation
If we add a space, it will switch to filling out the current_level
argument, showing us a description or explanation of the command. We can also see the fields for the rest of the required parameters.
We can navigate through parameters by pressing Tab and Shift+Tab.
When you are done filling out all required parameters, the available optional parameters will show for you to fill if you need to.
There are some argument validations that can be defined, so you get feedback on your values before sending the command:
Unlike chat 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.
Argument Options¶
Some command arguments will have predefined options, so you can choose from them.
Special Arguments¶
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 might not 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:
Argument Autocompletion¶
While Argument Options allow setting a number of predefined options, the number of possible options is limited, and they are the same for everyone. Some commands offer a different alternative: autocompletion.
Autocompletion allows NabBot to provide you with options based on your input, allowing you to easily navigate through more options, or even provide multiple ways to search for something.
Other commands provide alternate ways to search, for example, the /imbuement
command lets you search for an imbuement by its effect.
Permissions and controls¶
Application commands lets you personalize their access settings directly on Discord. You can control which roles or users can use certain commands or in which channels can the commands be used.
In order to access command settings, click on your server's name in the top left corner, then select the Server Settings ⚙️ option. In the Apps section, select Integrations. Search for NabBot in the Bots and Apps section and click on Manage.
In this section you can see the global permission settings and the list of all registered commands. Note that only "top level" commands are displayed, here, and not "subcommands" such as /event create
. You are only able to modify settings for entire commands and their subcommands, not granularly by subcommand.
Certain commands have default permissions set by us, so when the bot is just added to the server, they are not available to anyone. For example, the /settings
command initially requires Manage Server
permission, but afterward you can edit its settings to allow any roles or users you want.
By default, a command will be usable by everyone with the Use Application Commands
permission in any channel. As shown in the image above, this command has default permissions, but they can be overriden.
In the previous image, we have defined the following for the /respawn-manage
command:
- Only members with the role @Vice Leader can use it.
- Member @galarzaa cannot use it, regardless of their roles.
- The command can only be used in the channel #commands.
Note
Note that the server owner and members with the Administrator command will always be able to use all commands, anywhere.
Warning
Be careful when adding role & member overrides, you could give access to unwanted users to commands that can do irreversible damage to your server settings.