Table of Contents

Localizations

To localize application commands, you need to use ILocalizationsProvider. You specify it in the configuration.

Specifying the localizations provider

The samples below show how to specify the JsonLocalizationsProvider.

builder.Services
    .AddApplicationCommands(options =>
    {
        options.LocalizationsProvider = new JsonLocalizationsProvider();
    })

Localizing commands with the JsonLocalizationsProvider

The JsonLocalizationsProvider employs JSON files to localize commands. By default, these JSON files are expected to reside in the Localizations directory, with each file named after its respective locale in the format {locale}.json. For instance, a Polish localization file might be named pl.json. A list of supported locales can be found here.

Example

The file below shows Polish localization of permissions and animal commands.

{
  "commands": {
    "animal": {
      "name": "zwierzę",
      "description": "Wysyła zwierzę, które wybrałeś",
      "parameters": {
        "animal": {
          "name": "zwierzę",
          "description": "Zwierzę do wysłania"
        }
      }
    },
    "permissions": {
      "name": "uprawnienia",
      "description": "Zarządza uprawnieniami",
      "subcommands": {
        "user": {
          "name": "użytkownik",
          "description": "Zarządza uprawnienia użytkownika",
          "subcommands": {
            "show": {
              "name": "pokaż",
              "description": "Pokazuje uprawnienia użytkownika",
              "parameters": {
                "user": {
                  "name": "użytkownik",
                  "description": "Użytkownik, którego uprawnienia chcesz zobaczyć"
                }
              }
            }
          }
        },
        "role": {
          "name": "rola",
          "description": "Zarządza uprawnieniami roli",
          "subcommands": {
            "show": {
              "name": "pokaż",
              "description": "Pokazuje uprawnienia roli",
              "parameters": {
                "role": {
                  "name": "rola",
                  "description": "Rola, której uprawnienia chcesz zobaczyć"
                }
              }
            }
          }
        }
      }
    }
  },
  "enums": {
    "MyBot.Animal": {
      "Dog": "Pies",
      "Cat": "Kot",
      "Fish": "Ryba",
      "GuineaPig": "Świnka morska"
    }
  }
}

Here are the commands.

using NetCord.Services.ApplicationCommands;

namespace MyBot;

public class AnimalModule : ApplicationCommandModule<ApplicationCommandContext>
{
    [SlashCommand("animal", "Sends the animal you selected")]
    public static string Animal(
        [SlashCommandParameter(Description = "Animal to send")] Animal animal)
    {
        return animal.ToString();
    }
}

public enum Animal
{
    Dog,
    Cat,
    Fish,
    [SlashCommandChoice("Guinea Pig")]
    GuineaPig,
}
using NetCord;
using NetCord.Services.ApplicationCommands;

namespace MyBot;

[SlashCommand("permissions", "Manages permissions")]
public class PermissionsModule : ApplicationCommandModule<ApplicationCommandContext>
{
    [SubSlashCommand("user", "Manages user permissions")]
    public class UserPermissionsModule : ApplicationCommandModule<ApplicationCommandContext>
    {
        [SubSlashCommand("show", "Shows user permissions")]
        public static string Show(
            [SlashCommandParameter(Description = "The user whose permissions you want to see")] GuildUser user)
        {
            return ((GuildInteractionUser)user).Permissions.ToString();
        }
    }

    [SubSlashCommand("role", "Manages role permissions")]
    public class RolePermissionsModule : ApplicationCommandModule<ApplicationCommandContext>
    {
        [SubSlashCommand("show", "Shows role permissions")]
        public static string Show(
            [SlashCommandParameter(Description = "The channel whose permissions you want to see")] IGuildChannel channel)
        {
            return ((IInteractionChannel)channel).Permissions.ToString();
        }
    }
}