#Using modules for slash command handling but not definition

1 messages · Page 1 of 1 (latest)

royal holly
#

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.

hearty ember
#
  1. use interaction framework
  2. you can use autofill results
royal holly
#

Would autocomplete show all the options right away?

hearty ember
#

it takes a bit to load but its like less than a second

#

you can also implement something like a search bar and such its pretty cool

#

just note the user can still input any value if they choose not to select anything so you still need validation