Table of Contents

Class SlashCommandBuilder

Namespace
Discord
Assembly
Discord.Net.Core.dll

Represents a class used to build slash commands.

public class SlashCommandBuilder
Inheritance
SlashCommandBuilder
Inherited Members

Fields

MaxDescriptionLength

Returns the maximum length of a commands description allowed by Discord.

public const int MaxDescriptionLength = 100

Field Value

int

MaxNameLength

Returns the maximum length a commands name allowed by Discord

public const int MaxNameLength = 32

Field Value

int

MaxOptionsCount

Returns the maximum count of command options allowed by Discord

public const int MaxOptionsCount = 25

Field Value

int

Properties

ContextTypes

Gets the context types this command can be executed in. null if not set.

public HashSet<InteractionContextType> ContextTypes { get; set; }

Property Value

HashSet<InteractionContextType>

DefaultMemberPermissions

Gets or sets the default permission required to use this slash command.

public GuildPermission? DefaultMemberPermissions { get; set; }

Property Value

GuildPermission?

Description

Gets or sets a 1-100 length description of this slash command

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>

IntegrationTypes

Gets the installation method for this command. null if not set.

public HashSet<ApplicationIntegrationType> IntegrationTypes { get; set; }

Property Value

HashSet<ApplicationIntegrationType>

IsDMEnabled

Gets or sets whether or not this command can be used in DMs.

[Obsolete("This property will be deprecated soon. Configure with ContextTypes instead.")]
public bool IsDMEnabled { get; set; }

Property Value

bool

IsDefaultPermission

Gets or sets whether the command is enabled by default when the app is added to a guild

public bool IsDefaultPermission { get; set; }

Property Value

bool

IsNsfw

Gets or sets whether or not this command is age restricted.

public bool IsNsfw { get; set; }

Property Value

bool

Name

Gets or sets the name of this slash command.

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 the options for this command.

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

Property Value

List<SlashCommandOptionBuilder>

Methods

AddDescriptionLocalization(string, string)

Adds a new entry to the Description collection.

public SlashCommandBuilder AddDescriptionLocalization(string locale, string description)

Parameters

locale string

Locale of the entry.

description string

Localized string for the description field.

Returns

SlashCommandBuilder

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 SlashCommandBuilder AddNameLocalization(string locale, string name)

Parameters

locale string

Locale of the entry.

name string

Localized string for the name field.

Returns

SlashCommandBuilder

The current builder.

Exceptions

ArgumentException

Thrown if locale is an invalid locale string.

AddOption(SlashCommandOptionBuilder)

Adds an option to this slash command.

public SlashCommandBuilder AddOption(SlashCommandOptionBuilder option)

Parameters

option SlashCommandOptionBuilder

The option to add.

Returns

SlashCommandBuilder

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 SlashCommandBuilder AddOption(string name, ApplicationCommandOptionType type, string description, bool? isRequired = null, bool? isDefault = null, 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 is set to 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 name 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

SlashCommandBuilder

The current builder.

AddOptions(params SlashCommandOptionBuilder[])

Adds a collection of options to the current slash command.

public SlashCommandBuilder AddOptions(params SlashCommandOptionBuilder[] options)

Parameters

options SlashCommandOptionBuilder[]

The collection of options to add.

Returns

SlashCommandBuilder

The current builder.

Build()

Build the current builder into a SlashCommandProperties class.

public SlashCommandProperties Build()

Returns

SlashCommandProperties

A SlashCommandProperties that can be used to create slash commands.

WithContextTypes(params InteractionContextType[])

Sets context types this command can be executed in.

public SlashCommandBuilder WithContextTypes(params InteractionContextType[] contextTypes)

Parameters

contextTypes InteractionContextType[]

Context types the command can be executed in.

Returns

SlashCommandBuilder

The builder instance.

WithDMPermission(bool)

Sets whether or not this command can be used in dms.

[Obsolete("This method will be deprecated soon. Configure using WithContextTypes instead.")]
public SlashCommandBuilder WithDMPermission(bool permission)

Parameters

permission bool

true if the command is available in dms, otherwise false.

Returns

SlashCommandBuilder

The current builder.

WithDefaultMemberPermissions(GuildPermission?)

Sets the default member permissions required to use this application command.

public SlashCommandBuilder WithDefaultMemberPermissions(GuildPermission? permissions)

Parameters

permissions GuildPermission?

The permissions required to use this command.

Returns

SlashCommandBuilder

The current builder.

WithDefaultPermission(bool)

Sets the default permission of the current command.

public SlashCommandBuilder WithDefaultPermission(bool value)

Parameters

value bool

The default permission value to set.

Returns

SlashCommandBuilder

The current builder.

WithDescription(string)

Sets the description of the current command.

public SlashCommandBuilder WithDescription(string description)

Parameters

description string

The description of this command.

Returns

SlashCommandBuilder

The current builder.

WithDescriptionLocalizations(IDictionary<string, string>)

Sets the DescriptionLocalizations collection.

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

Parameters

descriptionLocalizations IDictionary<string, string>

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

Returns

SlashCommandBuilder

Exceptions

ArgumentNullException

Thrown if descriptionLocalizations is null.

ArgumentException

Thrown if any dictionary key is an invalid locale string.

WithIntegrationTypes(params ApplicationIntegrationType[])

Sets the installation method for this command.

public SlashCommandBuilder WithIntegrationTypes(params ApplicationIntegrationType[] integrationTypes)

Parameters

integrationTypes ApplicationIntegrationType[]

Installation types for this command.

Returns

SlashCommandBuilder

The builder instance.

WithName(string)

Sets the field name.

public SlashCommandBuilder WithName(string name)

Parameters

name string

The value to set the field name to.

Returns

SlashCommandBuilder

The current builder.

WithNameLocalizations(IDictionary<string, string>)

Sets the NameLocalizations collection.

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

Parameters

nameLocalizations IDictionary<string, string>

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

Returns

SlashCommandBuilder

Exceptions

ArgumentNullException

Thrown if nameLocalizations is null.

ArgumentException

Thrown if any dictionary key is an invalid locale string.

WithNsfw(bool)

Sets whether or not this command is age restricted.

public SlashCommandBuilder WithNsfw(bool permission)

Parameters

permission bool

true if the command is age restricted, otherwise false.

Returns

SlashCommandBuilder

The current builder.