I need to define my slash commands with choices that may change over time, this means that I can't use annotations to define them.
Here's what I have so far:
public async Task InitializeAsync()
{
var serverData = JsonSerializer.Deserialize<IEnumerable<ServerData>>(
await File.ReadAllTextAsync("./servers.json"));
var serverSelectionList = new SlashCommandOptionBuilder()
.WithName("server")
.WithRequired(true)
.WithDescription("The name of the server. All servers are shown in the selection.");
foreach (var data in serverData)
{
serverSelectionList
.AddChoice(data.Name, data.Id)
.WithType(ApplicationCommandOptionType.String);
}
var commands = new[]
{
new SlashCommandBuilder()
.WithName("start")
.WithDescription("Starts a specified server. If the server host is off this will turn it on.")
.AddOption(serverSelectionList),
...
};
foreach (var command in commands)
{
await _discord.CreateGlobalApplicationCommandAsync(command.Build());
}
await _interactions.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
}
Can't really figure out how to define the commands here and leave the handling of them only up to the module files.