Kuylar.DSharpPlus.SlashCommands 1.2.0

.NET 5.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package Kuylar.DSharpPlus.SlashCommands --version 1.2.0
NuGet\Install-Package Kuylar.DSharpPlus.SlashCommands -Version 1.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kuylar.DSharpPlus.SlashCommands" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kuylar.DSharpPlus.SlashCommands --version 1.2.0
#r "nuget: Kuylar.DSharpPlus.SlashCommands, 1.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Kuylar.DSharpPlus.SlashCommands as a Cake Addin
#addin nuget:?package=Kuylar.DSharpPlus.SlashCommands&version=1.2.0

// Install Kuylar.DSharpPlus.SlashCommands as a Cake Tool
#tool nuget:?package=Kuylar.DSharpPlus.SlashCommands&version=1.2.0


You must use the nightly versions of DSharpPlus to use this package. Make sure to enable the Pre-release checkbox in your NuGet manager

This is a "better" replacement for the current DSharpPlus. Most of the same documentation will also apply to this extension.

Localization tutorial

WARNING: In the time of writing this document (25 March 2022), slash command localization are in open beta and not available right away. Before developing them, make sure you enabled the build override (can be found in the https://discord.gg/discord-developers server)

To localize your slash commands, you will need a Localization Provider. An example localization provider can be seen below.

// Warning: This is an example. PLEASE do not write a localization provider using ifs and switches
public class LocalizationProvider : ILocalizationProvider
	public string GetLocalizedString(LocalizationContext localizationContext, Localization language, string key)
		if (key is not ("color" or "colorDescription")) return null;
		if (localizationContext is not (LocalizationContext.SlashCommandName or LocalizationContext
			.SlashCommandDescription)) return null;

		switch (language)
			case Localization.AmericanEnglish:
				if (key == "color") return "Color";
				if (key == "colorDescription") return "Get a color!";
			case Localization.BritishEnglish:
				if (key == "coloor") return "Colour";
				if (key == "colorDescription") return "Get a colour!";
			default: return null;

		return null;

As you can see, we use the keys and the localization context to make sure that were translating into the correct string.

After adding a localization provider, you can add a slash command like so:

// See how the keys and these values match each other
[SlashCommand("color", "colorDescription", applyLocalization: true)]
public async Task LocalTestCommand(InteractionContext ctx) => await ctx.CreateResponseAsync("You get **blue**!");

And don't forget to register our localization provider

SlashCommandsExtension slash = _client.UseSlashCommands(new SlashCommandsConfiguration
	LocalizationProvider = new LocalizationProvider()

If you did all these correctly, the command should appear differently if you set your Discord client when you change your client's language between English UK and English US.

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
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 211 7/9/2022
1.2.2 204 6/24/2022
1.2.1 176 5/30/2022
1.2.0 198 4/28/2022
1.1.3 167 4/17/2022
1.1.2 178 4/16/2022
1.1.1 187 4/14/2022
1.1.0 190 4/9/2022
1.0.11 176 4/9/2022
1.0.10 192 3/25/2022
1.0.9 194 3/6/2022
1.0.8 189 2/27/2022
1.0.7 262 2/4/2022
1.0.6 188 2/3/2022
1.0.5 203 1/19/2022
1.0.4 268 1/15/2022
1.0.3 183 12/27/2021
1.0.2 155 12/25/2021
1.0.1 154 12/24/2021
1.0.0 167 12/23/2021