![]() |
VOOZH | about |
dotnet add package Remora.Discord.Commands --version 30.0.0
NuGet\Install-Package Remora.Discord.Commands -Version 30.0.0
<PackageReference Include="Remora.Discord.Commands" Version="30.0.0" />
<PackageVersion Include="Remora.Discord.Commands" Version="30.0.0" />Directory.Packages.props
<PackageReference Include="Remora.Discord.Commands" />Project file
paket add Remora.Discord.Commands --version 30.0.0
#r "nuget: Remora.Discord.Commands, 30.0.0"
#:package Remora.Discord.Commands@30.0.0
#addin nuget:?package=Remora.Discord.Commands&version=30.0.0Install as a Cake Addin
#tool nuget:?package=Remora.Discord.Commands&version=30.0.0Install as a Cake Tool
This package provides glue code for using Remora.Commands with
Remora.Discord, adding appropriate conditions, autocompletion, type parsers,
and uniform UX for Remora-based applications.
Most of the library's functionality is offloaded to Remora.Commands, for which
documentation is available at its repository. Beyond this, the structure of
the library revolves around concepts that should be relatively familiar to users
of other Discord libraries.
Take a look in for an overview of the various types supported
as first-class parameters, beyond what Remora.Commands provides out of the
box.
For each command interaction that is received by your application, a matching
appropriate command is identified in your registered command trees, and is
executed with an implementation of ICommandContext, which provides contextual
information about the command environment (such as guilds, users, additional
data payloads, etc).
Furthermore, any autocompletion requests are routed to implementations of
IAutocompleteProvider, enabling you to provide bot-driven autocompletion of
command parameters.
To enable commands, call the following method on your dependency injection container.
services.AddDiscordCommands(enableSlash: true);
Note that slash commands are not enabled by default, and you must opt into them
by passing true as above.
Once you've added the command services and instantiated your service container, you must register your command tree(s) with Discord.
Inject or retrieve the SlashService from your container in an appropriate way,
and then call
await slashService.UpdateSlashCommandsAsync();
This will register the default command tree globally; optionally, you may register a different named tree, or register the tree at a guild level.
await slashService.UpdateSlashCommandsAsync(guildID: myServerID, treeName: myTreeName);
Not every feature supported by Remora.Commands is supported by Discord - if
you end up using incompatible features, an exception will be thrown at this
point.
Remora.Discord.Commands exposes a number of attributes you can use to influence or configure the way your commands are translated to Discord's slash command UX.
For the most part, these attributes map directly to fields or properties on Discord's application command object, but some have more specialized uses.
ChannelTypesSets the channel types that should be show in Discord's autocompletion when a user is typing.
Can be applied to Snowflake or IPartialChannel (and implementors)-typed
command parameters.
DiscordDefaultDMPermissionSets the default DM accessibility for a group or command.
Can be applied to top-level groups or commands. The attribute is not compatible with nested groups or commands, and will produce an exception if applied to those.
DiscordDefaultMemberPermissionsSets the default member permissions required for a user to use a group or command.
Can be applied to top-level groups or commands. The attribute is not compatible with nested groups or commands, and will produce an exception if applied to those.
DiscordNsfwSets whether the group or command is age-restricted and hidden or otherwise made unavailable in open channels.
Can be applied to top-level groups or commands. The attribute is not compatible with nested groups or commands, and will produce an exception if applied to those.
DiscordTypeHintHints Discord's autocompletion about the type of the parameter it is applied to, allowing only certain types of autocompleted input data.
Can be applied to any parameter, but is typically most useful for
Snowflake-typed parameters.
ExcludeFromChoicesRemoves the marked enumeration member from Discord's autocomplete list.
Can be applied to enumeration members.
ExcludeFromSlashCommandsExcludes the marked group or command from the slash command UI. This is primarily useful when you have certain commands which use incompatible Remora.Commands features, since it also removes all restrictions that would otherwise come from being a slash command.
Can be applied to groups and commands.
MinValueMarks a numeric parameter as having a minimum allowed value. This restricts Discord's autocompletion and client-side validation to the specified range.
The range is inclusive.
Can be applied to any parameter which has a numeric C# type.
MaxValueMarks a numeric parameter as having a maximum allowed value. This restricts Discord's autocompletion and client-side validation to the specified range.
The range is inclusive.
Can be applied to any parameter which has a numeric C# type.
SuppressInteractionResponseThis attribute prevents Remora from automatically sending an interaction response on your behalf when receiving a slash command (or similar interaction, such as a context menu click or button press). If you suppress the response, you must send one yourself within a few seconds of entering user code or Discord will consider the interaction failed.
Can be applied to groups and commands.
Discord also supports context menu items on users and messages, which are treated as special slash commands by their system.
These commands have some additional restrictions.
To mark a command as either a User or a Message command, apply the
CommandType attribute.
A User command must take a single parameter named user.
A Message command must take a single parameter named message.
In both cases, the data passed to the command will be a string containing the
user or message's ID; typically, this means you'd want to declare the parameter
with a type that can parse this ID into the entity you want. IUser or
IMessage is probably a good bet, but you can use any type you want as long as
its parser understands a Snowflake in string form.
Context menus also have relaxed rules when it comes to command names, and you can use both varied capitalization as well as whitespace.
[Command("My User Command")]
[CommandType(ApplicationCommandType.User)]
public async Task<IResult> MyUserCommand(IUser user)
{
// ...
}
If you want to create messages with a uniform UX, you may use the
FeedbackService for various message types, such as notices, successes,
failures, etc. The styling of these messages is controlled by an
IFeedbackTheme, of which there are two provided by default. These themes map
to Discord's own dark and light themes, respectively.
You may also implement your own theme and register it with the dependency injection container.
To provide autocomplete options while users of your application type, create a
class that implements either IAutocompleteProvider<T> (for autocompletion of
specific parameter types) or IAutocompleteProvider (for generic
autocompletion).
public class MyAutocompleteProvider : IAutocompleteProvider
{
public string Identity => "autocomplete::my-provider";
public ValueTask<IReadOnlyList<IApplicationCommandOptionChoice>> GetSuggestionsAsync
(
IReadOnlyList<IApplicationCommandInteractionDataOption> options,
string userInput,
CancellationToken ct = default
)
{
// ...
}
}
You may suggest up to 25 choices when your provider is invoked.
In order to select which autocomplete provider to use, apply the
AutocompleteAttribute to the appropriate parameters in your command groups. If
you're using the type-specific autocomplete provider, this is not required.
If a command can't be successfully prepared from whatever the user sends (due to malformed input, parsing failures, failed conditions etc.), the command's "preparation" is considered failed.
In many cases, it's useful to hook into this event in order to provide the end user with helpful information about what they did wrong or why the command didn't work.
This can be accomplished by registering a preparation error event, which is a
class that implements IPreparationErrorEvent.
public class MyPreparationErrorEvent : IPreparationErrorEvent
{
public Task<Result> PreparationFailed(IOperationContext context, IResult preparationResult, CancellationToken ct = default)
{
// ...
}
}
...
services.AddPreparationErrorEvent<MyPreparationErrorEvent>();
The preparation result contains information about the error - try checking for
things like CommandNotFoundError or ParameterParsingError when you get a
preparation error.
If you return an error in a preparation error event, the command invocation is cancelled, and never progresses to the real execution stage.
By default, user- or environment-caused preparation errors don't produce any log messages or user-facing output. It's up to you to decide if and how you want to handle these.
Note that if you register multiple preparation events, they will run sequentially within the same service scope. Order is not guaranteed, but typically ends up being the same as registration order. Every event will get a chance to run even if one of them fails, but failure of any of the events is considered a collective failure, and will cause the command invocation to be cancelled.
In some cases, it may be useful to execute pieces of code before or after invocation of a command (checking GDPR consent, logging error messages, etc).
This can be accomplished by registering pre- and post-execution events, which
are classes which implement either IPreExecutionEvent or
IPostExecutionEvent, respectively.
public class MyPreExecutionEvent : IPreExecutionEvent
{
public Task<Result> BeforeExecutionAsync(ICommandContext context, CancellationToken ct = default)
{
// ...
}
}
...
services.AddPreExecutionEvent<MyPreExecutionEvent>();
If you return an error in a pre-execution event, the command invocation is cancelled, and never progresses to the real execution stage. If you return an error in a post-execution event, this is treated as if the command itself had failed, which may be useful for things like scrubbing database transactions.
Note that if you register multiple pre- or post-execution events, they will run sequentially within the same service scope. Order is not guaranteed, but typically ends up being the same as registration order. Every event will get a chance to run even if one of them fails, but failure of any of the events is considered a collective failure. In the case of pre-execution events, this will cause the command invocation to be cancelled.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Remora.Discord.Commands:
| Package | Downloads |
|---|---|
|
Remora.Discord
Metapackage for Remora.Discord's various components |
|
|
Remora.Discord.Interactivity
Framework for using Discord's interaction-driven message components |
|
|
Remora.Discord.Extensions
Utilities and components which extend upon Remora.Discord's base resources |
|
|
AraHaan.Remora.Extensions
A package that extends Remora.Discord with additional functionality. Extensions: - AddRoles (extends IDiscordRestGuildAPI to allow adding discord roles in bulk) - RemoveRoles (extends IDiscordRestGuildAPI to allow removing discord roles in bulk) - RunBotConsoleAsync (extends IHostBuilder to allow an cleanup operation to be done on application shutdown, requires a type to derive from IBotServiceConfigurator) - DownloadAsync (extends DownloadAsync to download a discord attackment to a stream) - DownloadStringAsync (extends DownloadAsync to download a discord attackment to a string) - DownloadToFileAsync (extends DownloadAsync to download a discord attackment to a file) - AddDiscordGatewayClientOptions (extends IServiceCollection to allow adding the gateway client options using a factory) - AddSlashUpdateService (extends IServiceCollection to allow adding the SlashUpdateService background service to the service collection) - Configure<T> (extends IServiceProvider to allow the client options to be configured after the service provider is created) Types: - AraHaan.Remora.Extensions.Hosting.Host (A special host class that makes the IBotServiceConfigurator system work) - Note: When using this type ensure that "using Microsoft.Extensions.Hosting" is not used otherwise it will conflict. I have told Microsoft about my need to extend this but they said that they do not think it's needed. - AraHaan.Remora.Extensions.Hosting.BotServiceConfiguratorBase (A base class for types to provide code that should run before configure of the services, code to configure the services, and code to run after shutdown of the generic host aka Microsoft.Extensions.Hosting) - AraHaan.Remora.Extensions.Options.SlashUpdateServiceOptions (An options type used to configure the SlashUpdateService) - AraHaan.Remora.Extensions.Services.SlashUpdateService (An BackgroundService used to update Discord slash commands) |
|
|
VTP.Remora.Discord.HTTPInteractions
Adds support for receiving interactions over HTTP to Remora.Discord |
Showing the top 1 popular GitHub repositories that depend on Remora.Discord.Commands:
| Repository | Stars |
|---|---|
|
lavalink4net/Lavalink4NET
Lavalink4NET is a Lavalink wrapper with node clustering, caching and custom players for .NET with support for Discord.Net, DSharpPlus, Remora, and NetCord.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 30.0.0 | 37,619 | 5/24/2025 |
| 29.0.0 | 15,088 | 2/13/2025 |
| 28.1.0 | 50,761 | 5/28/2024 |
| 28.0.2 | 26,402 | 2/5/2024 |
| 28.0.1 | 47,432 | 11/14/2023 |
| 28.0.0 | 29,865 | 7/24/2023 |
| 27.0.0 | 18,964 | 5/11/2023 |
| 26.2.3 | 2,197 | 3/20/2023 |
| 26.2.2 | 2,708 | 1/19/2023 |
| 26.2.1 | 1,993 | 1/10/2023 |
| 26.2.0 | 2,398 | 12/28/2022 |
| 26.1.1 | 2,323 | 12/13/2022 |
| 26.1.0 | 2,015 | 12/13/2022 |
| 26.0.0 | 1,410 | 12/10/2022 |
| 25.3.0 | 2,496 | 10/30/2022 |
| 25.2.4 | 19,041 | 9/2/2022 |
| 25.2.3 | 2,323 | 8/19/2022 |
| 25.2.2 | 2,616 | 7/28/2022 |
| 25.2.1 | 2,018 | 7/26/2022 |
| 25.2.0 | 1,824 | 7/26/2022 |
BREAKING: Components V2 support
Fix autocomplete
BREAKING: Replace Fuzzy Matching in EnumAutocompleteProvider to use String.Contains