The menu is not only sent when you call main_menu.send, but also every second after that. The reason for this is because menus automatically drop from players' screens in some games after 4 seconds. To combat that, we send the menu every second.
During send, we rebuild the menu, which will call your build_callback override if supplied as you have above. Because menus inherit from the 'list' type, when you append, you are appending the same option to the menu over and over.
If your menu should always stay the same, there should be no reason to override the build_callback. Just append all your items after you create the menu. Then it will always send the way it was created. If the menu needs to be dynamic, which is where you would actually want to override build_callback, it is best to first clear the menu in your built_callback override and then append all items that should be shown.
Syntax: Select all
def build_menu(menu, player_index):
menu.clear()
if Player(player_index).name == '12jdlovins':
menu.append(PagedOption("test"))
else:
menu.append(PagedOption("test2"))
main_menu = PagedMenu(
build_callback=build_menu
)
@SayCommand("!testmenu")
def _menu_command(command, index, team_only):
main_menu.send(index)
Or, at the very least, if you don't want to clear, check to see if any items you might need to add/remove are already options in the menu.
Syntax: Select all
def build_menu(menu, player_index):
if Player(player_index).name == '12jdlovins':
if option1 not in menu:
menu.append(option1)
if option2 in menu:
menu.remove(option2)
else:
if option2 not in menu:
menu.append(option2)
if option1 in menu:
menu.remove(option1)
main_menu = PagedMenu(
build_callback=build_menu
)
option1 = PagedOption("test")
option2 = PagedOption("test2")
@SayCommand("!testmenu")
def _menu_command(command, index, team_only):
main_menu.send(index)