Table of Contents

Parameters

Slash Commands

Slash commands support up to 25 parameters.

Optional parameters

To mark parameters as optional, give them a default value, example:

[SlashCommand("username", "Returns user's username")]
public string Username(User? user = null)
{
    user ??= Context.User;
    return user.Username;
}

Parameter name and description

You can change parameter name and parameter description using SlashCommandParameterAttribute, example:

[SlashCommand("power", "Raises a number to a power")]
public static string Power(
    [SlashCommandParameter(Name = "base", Description = "The base")] double @base,
    [SlashCommandParameter(Description = "The power")] double power = 2)
{
    return $"Result: {Math.Pow(@base, power)}";
}

Min and Max Values

You can specify min and max parameter values by setting MinValue and MaxValue properties in SlashCommandParameterAttribute. It's only possible for numeric types.

Min and Max Length

You can specify min and max parameter length by setting MinLength and MaxLength properties in SlashCommandParameterAttribute. It's only possible for text types.

Choices and Autocomplete

Choices are constants for a given parameter, autocomplete may depend on a text entered by a user.

Choices

Choices are automatically generated when you set enum as a parameter type, you can override choices' names using SlashCommandChoiceAttribute on enum fields, example:

[SlashCommand("animal", "Sends animal you selected")]
public static string Animal(Animal animal) => animal.ToString();
public enum Animal
{
    Dog,
    Cat,
    Fish,
    [SlashCommandChoice("Guinea Pig")]
    GuineaPig,
}

You can also define own choices in the Type Reader by overriding ChoicesProvider property or in SlashCommandParameterAttribute by setting ChoicesProviderType property.

Autocomplete

You can turn on autocomplete in Type Reader by overriding AutocompleteProviderType property or in SlashCommandParameterAttribute by setting AutocompleteProviderType property. You run it using ExecuteAutocompleteAsync(TAutocompleteContext, IServiceProvider?).

User Commands

User commands only support a single parameter of type User. It's is not required, but allows you to access the target user of the user command easily.

Message Commands

Message commands only support a single parameter of type RestMessage. It's is not required, but allows you to access the target message of the message command easily.