© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
97 replies
REAPER

Slash Command optional parameter [Answered]

Hi, I'm currently working on a poll command where I'm using SelectMenuBuilder and I want for there to be 2 required answers to create the poll. I want the rest of the answers to be optional. Is it possible to make parameters optional or will they always be required?

So far I've only been able to find the [Optional] but it only hides it when using the command, but I'm still required to enter all 8 answers to make the command work...

[SlashCommand("poll", "Create a poll where people can vote")]
        public async Task PollAsync(string Question, string answer1, string answer2, [Optional] string answer3, [Optional] string answer4, 
            [Optional] string answer5, [Optional] string answer6, [Optional] string answer7, [Optional] string answer8)
        {
            var pollBuilder = new SelectMenuBuilder()
                .WithPlaceholder("Select an option")
                .WithCustomId("menu-1")
                .WithMinValues(1)
                .WithMaxValues(1)
                .AddOption(answer1, "answer-1")
                .AddOption(answer2, "answer-2")
                .AddOption(answer3, "answer-3")
                .AddOption(answer4, "answer-4")
                .AddOption(answer5, "answer-5")
                .AddOption(answer6, "answer-6")
                .AddOption(answer7, "answer-7")
                .AddOption(answer8, "answer-8");

            var builder = new ComponentBuilder()
                .WithSelectMenu(pollBuilder);

            await RespondAsync(Question, components: builder.Build());
[SlashCommand("poll", "Create a poll where people can vote")]
        public async Task PollAsync(string Question, string answer1, string answer2, [Optional] string answer3, [Optional] string answer4, 
            [Optional] string answer5, [Optional] string answer6, [Optional] string answer7, [Optional] string answer8)
        {
            var pollBuilder = new SelectMenuBuilder()
                .WithPlaceholder("Select an option")
                .WithCustomId("menu-1")
                .WithMinValues(1)
                .WithMaxValues(1)
                .AddOption(answer1, "answer-1")
                .AddOption(answer2, "answer-2")
                .AddOption(answer3, "answer-3")
                .AddOption(answer4, "answer-4")
                .AddOption(answer5, "answer-5")
                .AddOption(answer6, "answer-6")
                .AddOption(answer7, "answer-7")
                .AddOption(answer8, "answer-8");

            var builder = new ComponentBuilder()
                .WithSelectMenu(pollBuilder);

            await RespondAsync(Question, components: builder.Build());
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

Slash command choices [Answered]
C#CC# / help
4y ago
Slash Command purge [Answered]
C#CC# / help
4y ago
❔ Optional function parameter
C#CC# / help
3y ago
Slash Command works but gives error? [Answered]
C#CC# / help
4y ago