Table of Contents

Class SlashCommandOptionBuilder

Namespace
Discord
Assembly
Discord.Net.Core.dll

Represents a class used to build options for the SlashCommandBuilder.

public class SlashCommandOptionBuilder
Inheritance
SlashCommandOptionBuilder
Inherited Members

Fields

ChoiceNameMaxLength

The max length of a choice's name allowed by Discord.

public const int ChoiceNameMaxLength = 100

Field Value

int

MaxChoiceCount

The maximum number of choices allowed by Discord.

public const int MaxChoiceCount = 25

Field Value

int

Properties

ChannelTypes

Gets or sets the allowed channel types for this option.

public List<ChannelType> ChannelTypes { get; set; }

Property Value

List<ChannelType>

Choices

Gets or sets the choices for string and int types for the user to pick from.

public List<ApplicationCommandOptionChoiceProperties> Choices { get; set; }

Property Value

List<ApplicationCommandOptionChoiceProperties>

Description

Gets or sets the description of this option.

public string Description { get; set; }

Property Value

string

DescriptionLocalizations

Gets the localization dictionary for the description field of this command.

public IReadOnlyDictionary<string, string> DescriptionLocalizations { get; }

Property Value

IReadOnlyDictionary<string, string>

IsAutocomplete

Gets or sets whether or not this option supports autocomplete.

public bool IsAutocomplete { get; set; }

Property Value

bool

IsDefault

Gets or sets whether or not this options is the first required option for the user to complete. only one option can be default.

public bool? IsDefault { get; set; }

Property Value

bool?

IsRequired

Gets or sets if the option is required.

public bool? IsRequired { get; set; }

Property Value

bool?

MaxLength

Gets or sets the maximum allowed length for a string input.

public int? MaxLength { get; set; }

Property Value

int?

MaxValue

Gets or sets the largest number value the user can input.

public double? MaxValue { get; set; }

Property Value

double?

MinLength

Gets or sets the minimum allowed length for a string input.

public int? MinLength { get; set; }

Property Value

int?

MinValue

Gets or sets the smallest number value the user can input.

public double? MinValue { get; set; }

Property Value

double?

Name

Gets or sets the name of this option.

public string Name { get; set; }

Property Value

string

NameLocalizations

Gets the localization dictionary for the name field of this command.

public IReadOnlyDictionary<string, string> NameLocalizations { get; }

Property Value

IReadOnlyDictionary<string, string>

Options

Gets or sets if this option is a subcommand or subcommand group type, these nested options will be the parameters.

public List<SlashCommandOptionBuilder> Options { get; set; }

Property Value

List<SlashCommandOptionBuilder>

Type

Gets or sets the type of this option.

public ApplicationCommandOptionType Type { get; set; }

Property Value

ApplicationCommandOptionType

Methods

AddChannelType(ChannelType)

Adds a channel type to the current option.

public SlashCommandOptionBuilder AddChannelType(ChannelType channelType)

Parameters

channelType ChannelType

The ChannelType to add.

Returns

SlashCommandOptionBuilder

The current builder.

AddChoice(string, double, IDictionary<string, string>)

Adds a choice to the current option.

public SlashCommandOptionBuilder AddChoice(string name, double value, IDictionary<string, string> nameLocalizations = null)

Parameters

name string

The name of the choice.

value double

The value of the choice.

nameLocalizations IDictionary<string, string>

Localization dictionary for the description field of this command.

Returns

SlashCommandOptionBuilder

The current builder.

AddChoice(string, int, IDictionary<string, string>)

Adds a choice to the current option.

public SlashCommandOptionBuilder AddChoice(string name, int value, IDictionary<string, string> nameLocalizations = null)

Parameters

name string

The name of the choice.

value int

The value of the choice.

nameLocalizations IDictionary<string, string>

The localization dictionary for to use the name field of this command option choice.

Returns

SlashCommandOptionBuilder

The current builder.

AddChoice(string, long, IDictionary<string, string>)

Adds a choice to the current option.

public SlashCommandOptionBuilder AddChoice(string name, long value, IDictionary<string, string> nameLocalizations = null)

Parameters

name string

The name of the choice.

value long

The value of the choice.

nameLocalizations IDictionary<string, string>

The localization dictionary to use for the name field of this command option choice.

Returns

SlashCommandOptionBuilder

The current builder.

AddChoice(string, float, IDictionary<string, string>)

Adds a choice to the current option.

public SlashCommandOptionBuilder AddChoice(string name, float value, IDictionary<string, string> nameLocalizations = null)

Parameters

name string

The name of the choice.

value float

The value of the choice.

nameLocalizations IDictionary<string, string>

The localization dictionary to use for the name field of this command option choice.

Returns

SlashCommandOptionBuilder

The current builder.

AddChoice(string, string, IDictionary<string, string>)

Adds a choice to the current option.

public SlashCommandOptionBuilder AddChoice(string name, string value, IDictionary<string, string> nameLocalizations = null)

Parameters

name string

The name of the choice.

value string

The value of the choice.

nameLocalizations IDictionary<string, string>

The localization dictionary for to use the name field of this command option choice.

Returns

SlashCommandOptionBuilder

The current builder.

AddDescriptionLocalization(string, string)

Adds a new entry to the DescriptionLocalizations collection.

public SlashCommandOptionBuilder AddDescriptionLocalization(string locale, string description)

Parameters

locale string

Locale of the entry.

description string

Localized string for the description field.

Returns

SlashCommandOptionBuilder

The current builder.

Exceptions

ArgumentException

Thrown if locale is an invalid locale string.

AddNameLocalization(string, string)

Adds a new entry to the NameLocalizations collection.

public SlashCommandOptionBuilder AddNameLocalization(string locale, string name)

Parameters

locale string

Locale of the entry.

name string

Localized string for the name field.

Returns

SlashCommandOptionBuilder

The current builder.

Exceptions

ArgumentException

Thrown if locale is an invalid locale string.

AddOption(SlashCommandOptionBuilder)

Adds a sub option to the current option.

public SlashCommandOptionBuilder AddOption(SlashCommandOptionBuilder option)

Parameters

option SlashCommandOptionBuilder

The sub option to add.

Returns

SlashCommandOptionBuilder

The current builder.

AddOption(string, ApplicationCommandOptionType, string, bool?, bool, bool, double?, double?, List<SlashCommandOptionBuilder>, List<ChannelType>, IDictionary<string, string>, IDictionary<string, string>, int?, int?, params ApplicationCommandOptionChoiceProperties[])

Adds an option to the current slash command.

public SlashCommandOptionBuilder AddOption(string name, ApplicationCommandOptionType type, string description, bool? isRequired = null, bool isDefault = false, bool isAutocomplete = false, double? minValue = null, double? maxValue = null, List<SlashCommandOptionBuilder> options = null, List<ChannelType> channelTypes = null, IDictionary<string, string> nameLocalizations = null, IDictionary<string, string> descriptionLocalizations = null, int? minLength = null, int? maxLength = null, params ApplicationCommandOptionChoiceProperties[] choices)

Parameters

name string

The name of the option to add.

type ApplicationCommandOptionType

The type of this option.

description string

The description of this option.

isRequired bool?

If this option is required for this command.

isDefault bool

If this option is the default option.

isAutocomplete bool

If this option supports autocomplete.

minValue double?

The smallest number value the user can input.

maxValue double?

The largest number value the user can input.

options List<SlashCommandOptionBuilder>

The options of the option to add.

channelTypes List<ChannelType>

The allowed channel types for this option.

nameLocalizations IDictionary<string, string>

Localization dictionary for the description field of this command.

descriptionLocalizations IDictionary<string, string>

Localization dictionary for the description field of this command.

minLength int?
maxLength int?
choices ApplicationCommandOptionChoiceProperties[]

The choices of this option.

Returns

SlashCommandOptionBuilder

The current builder.

AddOptions(params SlashCommandOptionBuilder[])

Adds a collection of options to the current option.

public SlashCommandOptionBuilder AddOptions(params SlashCommandOptionBuilder[] options)

Parameters

options SlashCommandOptionBuilder[]

The collection of options to add.

Returns

SlashCommandOptionBuilder

The current builder.

Build()

Builds the current option.

public ApplicationCommandOptionProperties Build()

Returns

ApplicationCommandOptionProperties

The built version of this option.

WithAutocomplete(bool)

Sets the current builders autocomplete field.

public SlashCommandOptionBuilder WithAutocomplete(bool value)

Parameters

value bool

The value to set.

Returns

SlashCommandOptionBuilder

The current builder.

WithDefault(bool)

Sets the current builders default field.

public SlashCommandOptionBuilder WithDefault(bool value)

Parameters

value bool

The value to set.

Returns

SlashCommandOptionBuilder

The current builder.

WithDescription(string)

Sets the current builders description.

public SlashCommandOptionBuilder WithDescription(string description)

Parameters

description string

The description to set.

Returns

SlashCommandOptionBuilder

The current builder.

WithDescriptionLocalizations(IDictionary<string, string>)

Sets the DescriptionLocalizations collection.

public SlashCommandOptionBuilder WithDescriptionLocalizations(IDictionary<string, string> descriptionLocalizations)

Parameters

descriptionLocalizations IDictionary<string, string>

The localization dictionary to use for the description field of this command option.

Returns

SlashCommandOptionBuilder

The current builder.

Exceptions

ArgumentNullException

Thrown if descriptionLocalizations is null.

ArgumentException

Thrown if any dictionary key is an invalid locale string.

WithMaxLength(int)

Sets the current builders max length field.

public SlashCommandOptionBuilder WithMaxLength(int length)

Parameters

length int

The value to set.

Returns

SlashCommandOptionBuilder

The current builder.

WithMaxValue(double)

Sets the current builders max value field.

public SlashCommandOptionBuilder WithMaxValue(double value)

Parameters

value double

The value to set.

Returns

SlashCommandOptionBuilder

The current builder.

WithMinLength(int)

Sets the current builders min length field.

public SlashCommandOptionBuilder WithMinLength(int length)

Parameters

length int

The value to set.

Returns

SlashCommandOptionBuilder

The current builder.

WithMinValue(double)

Sets the current builders min value field.

public SlashCommandOptionBuilder WithMinValue(double value)

Parameters

value double

The value to set.

Returns

SlashCommandOptionBuilder

The current builder.

WithName(string)

Sets the current builders name.

public SlashCommandOptionBuilder WithName(string name)

Parameters

name string

The name to set the current option builder.

Returns

SlashCommandOptionBuilder

The current builder.

WithNameLocalizations(IDictionary<string, string>)

Sets the NameLocalizations collection.

public SlashCommandOptionBuilder WithNameLocalizations(IDictionary<string, string> nameLocalizations)

Parameters

nameLocalizations IDictionary<string, string>

The localization dictionary to use for the name field of this command option.

Returns

SlashCommandOptionBuilder

The current builder.

Exceptions

ArgumentNullException

Thrown if nameLocalizations is null.

ArgumentException

Thrown if any dictionary key is an invalid locale string.

WithRequired(bool)

Sets the current builders required field.

public SlashCommandOptionBuilder WithRequired(bool value)

Parameters

value bool

The value to set.

Returns

SlashCommandOptionBuilder

The current builder.

WithType(ApplicationCommandOptionType)

Sets the current type of this builder.

public SlashCommandOptionBuilder WithType(ApplicationCommandOptionType type)

Parameters

type ApplicationCommandOptionType

The type to set.

Returns

SlashCommandOptionBuilder

The current builder.