Kuylar.DSharpPlus.SlashCommands 1.0.10

There is a newer version of this package available.
See the version list below for details.
dotnet add package Kuylar.DSharpPlus.SlashCommands --version 1.0.10                
NuGet\Install-Package Kuylar.DSharpPlus.SlashCommands -Version 1.0.10                
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.0.10" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kuylar.DSharpPlus.SlashCommands --version 1.0.10                
#r "nuget: Kuylar.DSharpPlus.SlashCommands, 1.0.10"                
#r directive can be used in F# Interactive and Polyglot Notebooks. 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.0.10

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

Kuylar.DSharpPlus.SlashCommands

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!";
				break;
			case Localization.BritishEnglish:
				if (key == "coloor") return "Colour";
				if (key == "colorDescription") return "Get a colour!";
				break;
			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 Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
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 546 7/9/2022
1.2.2 442 6/24/2022
1.2.1 427 5/30/2022
1.2.0 454 4/28/2022
1.1.3 428 4/17/2022
1.1.2 414 4/16/2022
1.1.1 450 4/14/2022
1.1.0 440 4/9/2022
1.0.11 421 4/9/2022
1.0.10 434 3/25/2022
1.0.9 455 3/6/2022
1.0.8 450 2/27/2022
1.0.7 506 2/4/2022
1.0.6 426 2/3/2022
1.0.5 429 1/19/2022
1.0.4 522 1/15/2022
1.0.3 314 12/27/2021
1.0.2 258 12/25/2021
1.0.1 321 12/24/2021
1.0.0 315 12/23/2021