-
-
Notifications
You must be signed in to change notification settings - Fork 740
Description
The Problem:
It is not possible to set the Name or Callback property of a CommandBuilder when using any of these methods on ModuleBuilder in Discord.Net.Interactions:
AddSlashCommandAddContextCommandAddComponentCommandAddAutocompleteCommand
The methods all share a similar signature. They allow the library consumer to configure the respective CommandBuilder instance by consuming an Action.
This Action does not allow the modification of either Name or Callback property as they are marked internal.
moduleBuilder.AddSlashCommand(slashCommandBuilder =>
{
slashCommandBuilder.Name = "name"; // Not allowed.
slashCommandBuilder.Callback = CreateCallback(); // Not allowed.
});Possible Solution:
Discord.Net.Commands solves this by offering an overload of AddCommand which takes a builder action, name, and callback.
The CommandBuilder offers a constructor overload that consumes the callback.
Adding this kind of overload to ModuleBuilder is probably the cleanest way to solve this.
Not only does this solve the issue but it helps to bring Commands and Interactions more in line.
Also, all affected CommandBuilder subtypes already offer the necessary constructor overload.
public ModuleBuilder AddSlashCommand(string name, ExecuteCallback callback, Action<SlashCommandBuilder> configure)
{
var command = new SlashCommandBuilder(this, name, callback);
configure(command);
_slashCommands.Add(command);
return this;
}
public ModuleBuilder AddContextCommand(string name, ExecuteCallback callback, Action<ContextCommandBuilder> configure)
{
var command = new ContextCommandBuilder(this, name, callback);
configure(command);
_contextCommands.Add(command);
return this;
}
public ModuleBuilder AddComponentCommand(string name, ExecuteCallback callback, Action<ComponentCommandBuilder> configure)
{
var command = new ComponentCommandBuilder(this, name, callback);
configure(command);
_componentCommands.Add(command);
return this;
}
public ModuleBuilder AddAutocompleteCommand(string name, ExecuteCallback callback, Action<AutocompleteCommandBuilder> configure)
{
var command = new AutocompleteCommandBuilder(this, name, callback);
configure(command);
_autocompleteCommands.Add(command);
return this;
}