Kuylar.DSharpPlus.SlashCommands 1.0.10

.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.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, 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.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 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 net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.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 217 7/9/2022
1.2.2 209 6/24/2022
1.2.1 181 5/30/2022
1.2.0 203 4/28/2022
1.1.3 172 4/17/2022
1.1.2 183 4/16/2022
1.1.1 192 4/14/2022
1.1.0 195 4/9/2022
1.0.11 181 4/9/2022
1.0.10 197 3/25/2022
1.0.9 199 3/6/2022
1.0.8 194 2/27/2022
1.0.7 267 2/4/2022
1.0.6 193 2/3/2022
1.0.5 208 1/19/2022
1.0.4 273 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