Remora.Discord.Commands
25.1.1
Prefix Reserved
Install-Package Remora.Discord.Commands -Version 25.1.1
dotnet add package Remora.Discord.Commands --version 25.1.1
<PackageReference Include="Remora.Discord.Commands" Version="25.1.1" />
paket add Remora.Discord.Commands --version 25.1.1
#r "nuget: Remora.Discord.Commands, 25.1.1"
// Install Remora.Discord.Commands as a Cake Addin
#addin nuget:?package=Remora.Discord.Commands&version=25.1.1
// Install Remora.Discord.Commands as a Cake Tool
#tool nuget:?package=Remora.Discord.Commands&version=25.1.1
Remora.Discord.Commands
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.
Structure
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 Parsers 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.
Usage
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.
Registering slash commands
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);
Remember to check the result of your command registration, as not every feature
supported by Remora.Commands
is supported by Discord.
User feedback
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.
Autocomplete
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.
Pre- and post-execution events
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.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows |
.NET Core | netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.1 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETStandard 2.1
- FuzzySharp (>= 2.0.2)
- Humanizer.Core (>= 2.14.1)
- NGettext (>= 0.6.7)
- Remora.Commands (>= 10.0.1)
- Remora.Discord.Gateway (>= 10.1.3)
- Remora.Extensions.Options.Immutable (>= 1.0.3)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net5.0
- FuzzySharp (>= 2.0.2)
- Humanizer.Core (>= 2.14.1)
- NGettext (>= 0.6.7)
- Remora.Commands (>= 10.0.1)
- Remora.Discord.Gateway (>= 10.1.3)
- Remora.Extensions.Options.Immutable (>= 1.0.3)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net6.0
- FuzzySharp (>= 2.0.2)
- Humanizer.Core (>= 2.14.1)
- NGettext (>= 0.6.7)
- Remora.Commands (>= 10.0.1)
- Remora.Discord.Gateway (>= 10.1.3)
- Remora.Extensions.Options.Immutable (>= 1.0.3)
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages (3)
Showing the top 3 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 |
|
VTP.RemoraHelpSystem
Provides a simple, modular help system for Remora.Discord. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Remora.Discord.Commands:
Repository | Stars |
---|---|
discord-csharp/MODiX
Discord Bot handling basic moderation needs, soon implements statistics.
|
Version | Downloads | Last updated | |
---|---|---|---|
25.1.1 | 48 | 6/29/2022 | |
25.1.0 | 57 | 6/27/2022 | |
25.0.3 | 114 | 6/23/2022 | |
25.0.2 | 147 | 6/20/2022 | |
25.0.1 | 81 | 6/19/2022 | |
25.0.0 | 113 | 6/18/2022 | |
24.0.0 | 102 | 6/14/2022 | |
23.1.1 | 164 | 6/8/2022 | |
23.1.0 | 153 | 6/3/2022 | |
23.0.2 | 212 | 5/25/2022 | |
23.0.1 | 126 | 5/23/2022 | |
23.0.0 | 264 | 5/15/2022 | |
22.0.0 | 162 | 5/10/2022 | |
21.0.1 | 194 | 5/8/2022 | |
21.0.0 | 183 | 5/3/2022 | |
20.2.2 | 175 | 4/28/2022 | |
20.2.1 | 97 | 4/28/2022 | |
20.2.0 | 123 | 4/25/2022 | |
20.1.4 | 222 | 4/18/2022 | |
20.1.3 | 111 | 4/18/2022 | |
20.1.2 | 415 | 3/21/2022 | |
20.1.1 | 191 | 3/17/2022 | |
20.1.0 | 121 | 3/15/2022 | |
20.0.1 | 633 | 2/20/2022 | |
20.0.0 | 144 | 2/19/2022 | |
20.0.0-rc1 | 58 | 2/14/2022 | |
19.0.3 | 144 | 2/14/2022 | |
19.0.2 | 391 | 1/27/2022 | |
19.0.1 | 401 | 1/18/2022 | |
19.0.0 | 107 | 1/17/2022 | |
18.0.0 | 108 | 1/17/2022 | |
17.0.0 | 194 | 1/11/2022 | |
16.1.0 | 9,316 | 1/2/2022 | |
16.0.3 | 179 | 1/1/2022 | |
16.0.2 | 298 | 12/23/2021 | |
16.0.1 | 131 | 12/23/2021 | |
16.0.0 | 158 | 12/21/2021 | |
15.0.0 | 326 | 12/16/2021 | |
14.0.4 | 186 | 12/11/2021 | |
14.0.3 | 199 | 12/5/2021 | |
14.0.2 | 1,973 | 11/26/2021 | |
14.0.1 | 6,004 | 11/24/2021 | |
14.0.0 | 1,095 | 11/20/2021 | |
13.2.2 | 874 | 11/9/2021 | |
13.2.1 | 246 | 11/7/2021 | |
13.2.0 | 273 | 11/6/2021 | |
13.0.0 | 202 | 11/3/2021 | |
12.1.0 | 359 | 10/30/2021 | |
12.0.1 | 260 | 10/30/2021 | |
12.0.0 | 304 | 10/28/2021 | |
11.0.4 | 1,552 | 10/15/2021 | |
11.0.3 | 856 | 10/7/2021 | |
11.0.1 | 399 | 10/3/2021 | |
11.0.0 | 253 | 10/2/2021 | |
10.2.1 | 259 | 9/30/2021 | |
10.2.0 | 237 | 9/27/2021 | |
10.1.0 | 202 | 9/26/2021 | |
10.0.7 | 213 | 9/26/2021 | |
10.0.6 | 262 | 9/24/2021 | |
10.0.5 | 260 | 9/23/2021 | |
10.0.4 | 250 | 9/16/2021 | |
10.0.3 | 351 | 9/15/2021 | |
10.0.2 | 350 | 9/8/2021 | |
10.0.1 | 1,229 | 9/4/2021 | |
10.0.0 | 238 | 9/4/2021 | |
9.1.1 | 382 | 8/26/2021 | |
9.1.0 | 257 | 8/26/2021 | |
9.0.1 | 1,377 | 8/21/2021 | |
9.0.0 | 261 | 8/21/2021 | |
8.3.1 | 356 | 8/18/2021 | |
8.3.0 | 284 | 8/12/2021 | |
8.2.2 | 232 | 8/11/2021 | |
8.2.1 | 220 | 8/11/2021 | |
8.2.0 | 233 | 8/11/2021 | |
8.1.0 | 171 | 8/9/2021 | |
8.0.1 | 329 | 8/2/2021 | |
8.0.0 | 247 | 8/2/2021 | |
7.0.0 | 279 | 8/2/2021 | |
6.0.0 | 306 | 7/31/2021 | |
5.1.0 | 384 | 7/31/2021 | |
5.0.0 | 332 | 7/29/2021 | |
4.1.1 | 282 | 7/28/2021 | |
4.1.0 | 215 | 7/28/2021 | |
4.0.5 | 324 | 7/27/2021 | |
4.0.4 | 289 | 7/22/2021 | |
4.0.3 | 294 | 7/17/2021 | |
4.0.2 | 270 | 7/14/2021 | |
4.0.1 | 345 | 7/12/2021 | |
4.0.0 | 247 | 7/11/2021 | |
3.10.13 | 256 | 7/5/2021 | |
3.10.12 | 297 | 7/3/2021 | |
3.10.11 | 216 | 7/1/2021 | |
3.10.10 | 468 | 6/14/2021 | |
3.10.9 | 203 | 6/10/2021 | |
3.10.9-beta1 | 249 | 5/30/2021 | |
3.10.8 | 387 | 5/28/2021 | |
3.10.7 | 274 | 5/23/2021 | |
3.10.6 | 281 | 5/20/2021 | |
3.10.5 | 193 | 5/11/2021 | |
3.10.4 | 232 | 5/11/2021 | |
3.10.3 | 263 | 5/4/2021 | |
3.10.2 | 239 | 4/22/2021 | |
3.10.1 | 224 | 4/15/2021 | |
3.10.0 | 295 | 4/10/2021 | |
3.9.0 | 193 | 4/8/2021 | |
3.8.0 | 262 | 4/5/2021 | |
3.7.5 | 290 | 4/4/2021 | |
3.7.4 | 254 | 3/29/2021 | |
3.7.3 | 258 | 3/29/2021 | |
3.7.2 | 278 | 3/28/2021 | |
3.7.1 | 246 | 3/27/2021 | |
3.7.0 | 266 | 3/27/2021 | |
3.6.0 | 265 | 3/26/2021 | |
3.5.4 | 248 | 3/25/2021 | |
3.5.3 | 255 | 3/25/2021 | |
3.5.2 | 199 | 3/22/2021 | |
3.5.1 | 284 | 3/16/2021 | |
3.5.0 | 244 | 3/16/2021 | |
3.4.2 | 292 | 3/14/2021 | |
3.4.1 | 231 | 3/13/2021 | |
3.4.0 | 253 | 3/11/2021 | |
3.3.1 | 227 | 3/11/2021 | |
3.3.0 | 315 | 3/6/2021 | |
3.2.2 | 276 | 3/1/2021 | |
3.2.1 | 322 | 3/1/2021 | |
3.2.0 | 215 | 2/28/2021 | |
3.1.2 | 258 | 2/28/2021 | |
3.1.1 | 206 | 2/24/2021 | |
3.1.0 | 231 | 2/23/2021 | |
3.0.0 | 198 | 2/23/2021 | |
2.0.6 | 246 | 2/22/2021 | |
2.0.5 | 218 | 2/22/2021 | |
2.0.4 | 223 | 2/21/2021 | |
2.0.3 | 276 | 2/13/2021 | |
2.0.2 | 282 | 2/12/2021 | |
2.0.1 | 165 | 2/11/2021 | |
2.0.0 | 183 | 2/10/2021 | |
1.3.13 | 194 | 2/6/2021 | |
1.3.12 | 219 | 2/5/2021 | |
1.3.11 | 186 | 1/29/2021 | |
1.3.10 | 194 | 1/27/2021 | |
1.3.9 | 248 | 1/21/2021 | |
1.3.8 | 231 | 1/21/2021 | |
1.3.7 | 236 | 1/20/2021 | |
1.3.6 | 210 | 1/17/2021 | |
1.3.5 | 253 | 1/10/2021 | |
1.3.4 | 265 | 1/10/2021 | |
1.3.3 | 209 | 1/10/2021 | |
1.3.2 | 275 | 1/9/2021 | |
1.3.1 | 304 | 1/1/2021 | |
1.3.0 | 312 | 1/1/2021 | |
1.2.1 | 235 | 12/30/2020 | |
1.2.0 | 218 | 12/27/2020 | |
1.1.2 | 211 | 12/26/2020 | |
1.1.1 | 224 | 12/26/2020 | |
1.1.0 | 302 | 12/26/2020 | |
1.0.1 | 356 | 12/25/2020 | |
1.0.0 | 222 | 12/25/2020 | |
1.0.0-beta9 | 226 | 12/18/2020 | |
1.0.0-beta8 | 194 | 12/10/2020 | |
1.0.0-beta7 | 211 | 11/26/2020 | |
1.0.0-beta6 | 189 | 11/15/2020 | |
1.0.0-beta5 | 237 | 11/14/2020 | |
1.0.0-beta4 | 218 | 11/9/2020 | |
1.0.0-beta11 | 175 | 12/23/2020 |
Update dependencies.