Skip to content

Selector Menu

yoshisman8 edited this page Jun 18, 2019 · 1 revision

Selector Menu

A selector menu is a menu that displays a list of options to the user. And then, using an Up/Down and a select button, the user has to pick between one of these options.

This is useful when letting the user pick between multiple search results.

Here's how you initialize it:

using Discord.Addon.InteractiveMenu;

MyClass[] Objects; // Both of these should have
string[] Options; // The exact same order of listed items

// The Name argument is what will be shown to the user above the listed options.
SelectorMenu Menu = new SelectorMenu("Multiple Entries were found.",Options,Objects);

After the menu is created, you pass it to the Menu Service

await MenuService.CreateMenu(Context,Menu,true); //By setting it to true, only the user who evoked the menu can interact

And lastly we get the user's choice, this is done by awaiting the menu's GetSelectedObject() method. The object passed to the menu is returned as a generic Object. This means casting it as the correct type will be required.

MyClass result = (MyClass)await Menu.GetSelectedObject();

Clone this wiki locally