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
MaxNameLength
Returns the maximum length a commands name allowed by Discord
public const int MaxNameLength = 32
Field Value
MaxOptionsCount
Returns the maximum count of command options allowed by Discord
public const int MaxOptionsCount = 25
Field Value
Properties
ContextTypes
Gets the context types this command can be executed in. null if not set.
public HashSet<InteractionContextType> ContextTypes { get; set; }
Property Value
DefaultMemberPermissions
Gets or sets the default permission required to use this slash command.
public GuildPermission? DefaultMemberPermissions { get; set; }
Property Value
Description
Gets or sets a 1-100 length description of this slash command
public string Description { get; set; }
Property Value
DescriptionLocalizations
Gets the localization dictionary for the description field of this command.
public IReadOnlyDictionary<string, string> DescriptionLocalizations { get; }
Property Value
IntegrationTypes
Gets the installation method for this command. null if not set.
public HashSet<ApplicationIntegrationType> IntegrationTypes { get; set; }
Property Value
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
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
IsNsfw
Gets or sets whether or not this command is age restricted.
public bool IsNsfw { get; set; }
Property Value
Name
Gets or sets the name of this slash command.
public string Name { get; set; }
Property Value
NameLocalizations
Gets the localization dictionary for the name field of this command.
public IReadOnlyDictionary<string, string> NameLocalizations { get; }
Property Value
Options
Gets or sets the options for this command.
public List<SlashCommandOptionBuilder> Options { get; set; }
Property Value
Methods
AddDescriptionLocalization(string, string)
Adds a new entry to the Description collection.
public SlashCommandBuilder AddDescriptionLocalization(string locale, string description)
Parameters
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
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
SlashCommandOptionBuilderThe 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
stringThe name of the option to add.
type
ApplicationCommandOptionTypeThe type of this option.
description
stringThe description of this option.
isRequired
bool?If this option is required for this command.
isDefault
bool?If this option is the default option.
isAutocomplete
boolIf 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
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
boolThe 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
stringThe 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
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
stringThe 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
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
Returns
- SlashCommandBuilder
The current builder.