Discord App Commands: A Comprehensive Guide

Author

Reads 894

Hands on White Computer Keyboard
Credit: pexels.com, Hands on White Computer Keyboard

The Discord app offers a wide range of commands that can enhance your experience, from basic features to advanced tools.

These commands can be used to manage your server, communicate with other users, and even automate tasks.

One of the most useful commands is the `!help` command, which provides a list of available commands and their functions.

You can also use the `!serverinfo` command to view information about your server, including its name, description, and member count.

To use these commands, you'll need to enable the "Developer Mode" in your Discord settings, which allows you to access advanced features and commands.

This mode also enables the "Inspect Element" feature, which allows you to view and edit the HTML code of Discord's interface.

By enabling Developer Mode, you'll unlock a world of possibilities for customizing and automating your Discord experience.

Here's an interesting read: Important Commands in Command Prompt

What is an app command?

App commands are a way to interact with your Discord application, and they come in three types: slash commands, context menu User commands, and context menu Message commands.

You might like: Common Openssl Commands

Credit: youtube.com, Discord Commands - A Complete List & Guide

Slash commands have a name, description, and a block of options, which help validate user input. The name and description help users find your command among many others.

Context menu User and Message commands are only a name to the user, so try to make the name descriptive. They're accessed by right-clicking (or long-pressing on mobile) a user or a message, respectively.

Both slash and context menu commands have Global and Guild variants, but global commands are available in every guild that adds your application. You can also make commands for a specific guild; they're only available in that guild.

There are limits to how many User and Message commands you can create, but you can check out their respective guide pages for specifics.

Related reading: Discord Commands for Bots

Creating and Editing Commands

Creating and editing commands is a crucial part of building a Discord bot. To create a command, you can build the command's structure using the ApplicationCommandRequest.Builder, and then use the RestClient to make the request to Discord.

Discover more: Pingtest Command

Credit: youtube.com, Discord.py: Creating Your First Slash Command Tutorial!

Commands have a TTL of 1 hour, meaning it will take up to 1 hour for a global command's changes to take effect in the Discord client. This is why it's recommended to use guild commands while developing and testing, and switch to global commands when ready to deploy.

You can create a guild command by defining the command's structure using JSON, and then configuring the Quarkus Discord Bot to register the command when your app starts. To do this, you'll need to create a JSON file in META-INF/commands with the command's details.

To edit a command, you can use the same ApplicationCommandRequest you built to create the command, along with the ApplicationCommandData that represents what Discord knows about your commands. Sometimes, you may just want to delete a command that's no longer needed.

Here's a summary of the steps to create and edit commands:

Remember, guild commands are recommended for development and testing, while global commands are best for deployment. And don't forget to configure your Quarkus Discord Bot to register your commands when your app starts!

Command Structure and Syntax

Credit: youtube.com, Creating a Stairs Command in Discord.py: Troubleshooting Syntax Errors

To create a command, you'll need to build its structure using the ApplicationCommandRequest.Builder. This is the foundation of your command, and it's what will allow you to interact with the Discord client.

Building the command's structure is a straightforward process. All you need to do is use the ApplicationCommandRequest.Builder to put the pieces together.

Remember, global commands have a TTL of 1 hour, which means it will take up to 1 hour for a global command's changes to take effect in the Discord client.

Converters

Converters are a powerful tool in Discord.py that make working with Discord models easy. They can convert a string into a specific Discord object, such as a Member or a Message.

To use a converter, you simply pass it as a parameter in your command function. For example, to receive a Member, you can pass MemberConverter as the converter.

The library has a default set of converters that have been written to be easy to use. These converters can intelligently convert the argument to the appropriate target type.

Here's a list of the equivalent converters for each Discord class:

By providing the converter, it allows us to use them as building blocks for another converter.

Subcommand Groups

Credit: youtube.com, Subcommand & Subcommand Groups (Discord.js + DJS-Commander)

Subcommand groups are a powerful way to organize your commands and make them more intuitive to use.

You can listen for subcommand groups by creating a class hierarchy that includes subcommands and subcommand groups. For example, you can create a class that listens for /foo baz commands and another class that listens for /foo bar baz commands.

Subcommand groups can be nested, allowing you to create a hierarchy of commands that are easy to navigate. This can be especially useful when you have a large number of commands and want to group related ones together.

A class that listens for /foo bar baz commands is a subcommand group of a class that listens for /foo baz commands.

Here's a summary of the class hierarchy for subcommand groups:

Note that the subcommand group /foo bar baz sub is a subcommand of the subcommand group /foo bar baz. This allows you to create a hierarchy of commands that are easy to navigate.

Command Interaction and Response

Credit: youtube.com, How to Respond to a Slash Command Interaction Without Sending a Message

Every command must take at least a single parameter, called the Context, which gives you access to the invocation context. This contains a lot of useful information, including the Guild, Message, and Author of the command.

The Context also implements the abc.Messageable interface, allowing you to send messages to the channel the command was used in using the Context.send() method.

To respond to a command, you have 3 seconds to respond before it times out. If you can return something immediately, use reply(). If it takes longer, use deferReply and then editReply or createFollowup when you're ready to respond with data.

You can listen for commands by creating a class with a method that returns Mono, Uni, Flux, or Multi. When you receive a command, you must acknowledge it by immediately replying.

Sometimes, you might want to send multiple responses to a command. You can do this by sending multiple followups as long as the interaction is valid for.

For more insights, see: How to Use Discord App

Credit: youtube.com, How To Turn On Use Application Commands On Discord

Here's a list of some built-in Integrated Slash Commands that you can use in your Discord server:

  • /giphy — Searches Giphy for a GIF by keyword.
  • /tenor — Searches Tenor for a GIF by keyword.
  • /shrug — Appends ¯\_(ツ)_/¯ to the end of your message if used with the option.
  • /tableflip — Appends (╯°□°)╯︵ ┻━┻ to the end of your message if used with the option.
  • /unflip — Appends ┬─┬ ノ( ゜-゜ノ) to the end of your message if used with the option.
  • /me — Italicizes an entire message.
  • /nick — Used to change your nickname in a server.
  • /thread — Starts a new thread in the channel.
  • /kick — Kick a user from the server.
  • /ban — Ban a user from the server.
  • /timeout — Place a user on chat timeout.
  • /msg — Quickly direct message a user.

Command Options and Parameters

Command options and parameters are a crucial part of Discord app commands, allowing you to create more interactive and engaging commands.

For hybrid commands, parameters are flattened into different parameters for the application command, making it easier to use decorators that refer to a parameter by name. This is equivalent to defining an application command with separate parameters.

The flag() function is a convenient way to pass descriptions inline, making it easier to document your commands. You can also use the name keyword argument to pass renames for the parameter, similar to the rename() decorator.

Note that certain annotations are unsupported due to Discord limitations, including typing.Tuple, typing.List, and typing.Dict.

Checks

Checks are a crucial part of command options and parameters, allowing you to control who can run a command.

You can return True to signal that the person can run the command, or return False to signal that they cannot. You can also raise a CommandError derived exception to signal the person cannot run the command.

Two Turned-on Flat Screen Computer Monitors on Desk
Credit: pexels.com, Two Turned-on Flat Screen Computer Monitors on Desk

There are three ways to register a check for a command: using the check() decorator, creating your own decorator, or using a built-in decorator like is_owner().

The is_owner() function is a built-in decorator that checks if the person running the command is the owner.

If multiple checks are specified, all of them must be True for the command to run. If any of the checks fail, the command will not be run.

Here's an example of how to use multiple checks:

  • guild_only() checks if the command is being run in a guild.
  • is_owner() checks if the person running the command is the owner.

If you want a more robust error system, you can derive from the CommandError exception and raise it instead of returning False. This will prevent the command from running and display a custom error message.

The Context class also implements some behavioural changes for various methods and attributes, making it easier to write code and handle errors.

Handling Options

Handling Options is a bit more complex than it seems. Only Chat Input commands support options, so if you're working with Message or User commands, you can skip this section.

Four People Using Laptop Computers and Smartphone
Credit: pexels.com, Four People Using Laptop Computers and Smartphone

You can get an option and assign a default value using the flag() function. This function accepts a description keyword argument to allow you to pass descriptions inline, making it easier to use.

The flag() function also supports the name keyword argument, which allows you to pass renames for the parameter, similar to the rename() decorator.

Note that not all annotations are supported due to Discord limitations. Specifically, typing.Tuple, typing.List, and typing.Dict are unsupported in hybrid command form.

Here's a quick summary of the limitations:

  • typing.Tuple
  • typing.List
  • typing.Dict

It's worth noting that only one flag converter is supported per hybrid command. This is because the flag converter's way of working makes it unlikely for a user to have two of them in one signature.

Command Authorization and Access

To use Application Commands within a guild, the guild must authorize your application with the applications.commands scope. This scope is a special OAuth2 scope for applications.

You can find this scope on your Discord application's OAuth2 screen, where you can select it and then use the link to add your bot to a server. Make sure to select the application.commands scope, as the bot scope is not enough.

For another approach, see: How to Add Spotify Music Bot to Discord

Credit: youtube.com, How to Add Ping Roles on Discord (2025)

To enable users in your guild to use your slash commands, they need to have the "Use Application Commands" permission on the guild. This permission is universal and can be found under Text Channel Permissions of any role, as well as in a channel's permissions overwrites.

Some built-in commands, such as /kick, /ban, /timeout, /thread, and /nick, require specific Discord permissions to use. For example, /kick requires the "Kick Members" permission, and /ban requires the "Ban Members" permission.

Here's a quick rundown of the permissions needed for some built-in commands:

  • /kick — Requires “Kick Members”
  • /ban — Requires “Ban Members”
  • /timeout — Requires “Timeout Members”
  • /thread — Requires “Create Public Thread”
  • /nick — Requires “Change Nickname”

Authorizing Your Bot

To authorize your bot, you need to add the applications.commands scope to your Discord application. This is a special OAuth2 scope that allows your bot to use application commands within a guild.

You can find this setting on your Discord application's OAuth2 screen. Make sure to select the application.commands scope from the list of available options.

Next, use the generated link to add your bot to a server. This will give your bot permission to use application commands within that guild.

To enable users in your guild to use your slash commands, they need to have the "Use Application Commands" permission on the guild.

Expand your knowledge: How to Add a Channel on Discord

Guild Command

Credit: youtube.com, How to Restrict Commands to Specific Guilds in discord.py

Creating a guild command is just as easy as creating a global command. You just need to include the Guild's ID in the process.

The permission "Use Application Commands" is a universal enabler or disabler for Slash Commands. You can find this permission under the Text Channel Permissions of any role and also in a channel's permissions overwrites.

Some built-in commands require specific permissions to function. For example, the /kick command requires the "Kick Members" permission, the /ban command requires the "Ban Members" permission, and so on.

Here's a list of built-in commands that require specific permissions:

  • /kick — Requires “Kick Members”
  • /ban — Requires “Ban Members”
  • /timeout — Requires “Timeout Members”
  • /thread — Requires “Create Public Thread”
  • /nick — Requires “Change Nickname”

To create a guild command, you need to use the GlobalCommandRegistrar, which is found in the Example Projects.

Command Advanced Features

Discord app commands offer a range of advanced features that take your server's functionality to the next level.

You can use slash commands to create custom actions, such as displaying a server's uptime or listing all members with a specific role.

Credit: youtube.com, Top 5 Features / System / Commands for your Discord Server in 2022

Slash commands can also be used to automate tasks, like sending a welcome message to new members or assigning a default role to users when they join.

The "Create Action" feature allows you to define a custom action that can be triggered by a slash command, making it easy to create complex workflows.

Hybrid

Hybrid commands are a powerful feature that allows you to define a command as both a text and a slash command without writing separate code for both counterparts.

To create a hybrid command, you'll need to decorate the command callback with the Bot.hybrid_command() decorator. This will enable the command to be invoked as both a text and a slash command.

You can create hybrid command groups and sub-commands using the Bot.hybrid_group() decorator. This allows you to create a command that can be invoked as a group, with sub-commands that can be bound to the callback of the parent group.

People Using Computers at Work
Credit: pexels.com, People Using Computers at Work

Some features of text commands are not supported on hybrid commands due to Discord limitations. These include variable number of arguments, group commands with a depth greater than 1, and most typing.Union types.

Here are some features that are currently not supported by hybrid commands:

  • Variable number of arguments. e.g. *arg:int
  • Group commands with a depth greater than 1.
  • Most typing.Union types.

Despite these limitations, hybrid commands support a wide range of features, including converters, checks, autocomplete, and flags. You can also use the flag() function to pass descriptions inline and the name keyword argument to pass renames for the parameter.

Bulk Overwrite

Bulk Overwrite is a powerful feature that allows you to replace existing commands with new ones, rather than updating them individually. It's perfect for making large changes to your commands.

To use Bulk Overwrite, you'll need a list of ApplicationCommandRequest. This method is more efficient than editing commands one by one, especially when you have many changes to make.

Bulk Overwrite doesn't just edit commands, it replaces them outright. This means you can make significant changes to your commands without having to worry about updating existing ones.

Command Error Handling and Logging

Credit: youtube.com, Python Discord Bot - Handling Command Errors

Command errors in discord app commands can be noisy and silent, but we can handle them with ease. We can use an error handler function decorated with error() to catch and handle errors local to a command itself.

The global error handler, on_command_error(), is called for every error reached and works like any other event. It takes two parameters: the Context and an exception derived from CommandError.

We can use a local error handler to handle errors specific to a command, and it's often more convenient than the global error handler. The first parameter of the local error handler is the Context, and the second one is an exception that is derived from CommandError.

A list of errors is found in the Exceptions page of the documentation, which we can refer to when creating our error handlers. By decorating our error handler function with error(), we can catch and handle errors in a clean and organized way.

Command User and Message Interaction

Credit: youtube.com, How to Create a Discord Command That Triggers Regardless of Additional Text

To listen for user or message commands, you can use methods annotated with @Command that declare a parameter of UserInteractionEvent or MessageInteractionEvent.

You can use Slash Commands by typing /, which will give you a list of available commands that you can type out or click on.

Subcommands and subcommand groups aren't supported for user and message commands, so you'll need to stick with the basics.

Some Slash Commands include extra "Options" like the "new_nick" Option on the "/nick" command, which allows you to pass information for the command to use.

You can use commands like "/me" to make an entire message italic, and "/nick" to quickly change your nickname on the server.

Command Receiving and Listening

Receiving and listening to commands are crucial steps in building a Discord app. You can receive application commands with a simple code, which can be customized to only receive slash commands.

The type of command you want to receive determines the code you'll use. For message commands and user commands, you'll use MessageInteractionEvent and UserInteractionEvent respectively.

Credit: youtube.com, How to make a Discord Bot using Discord.js || Part 2 || Listening For Messages and Ping Command

To get the initial reply in another part of your code, you'll need to use the code provided for receiving commands.

Listening to commands requires a class that defines the command method. Here's what you need to know:

In your command method, you can extract the value of the name option passed to your command. For example, you can extract the value of the name option passed to the foo command.

Once you receive a command, you need to acknowledge it. This is done by immediately replying to the command, as shown in the example.

Cora Stoltenberg

Junior Writer

Cora Stoltenberg is a skilled writer with a passion for crafting engaging content on a wide range of topics. Her expertise spans various categories, including Search Engine Optimization (SEO) Strategies, where she provides actionable tips and insights to help businesses improve their online presence. With a keen eye for detail and a knack for simplifying complex concepts, Cora's writing is both informative and accessible to readers of all levels.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.