Hi, I'm trying to add select menu options through a function.
This is the class where I create the view with the select menu and a function in it that creates the options for the menu:
lass SelectTrainerName(discord.ui.View):
def __init__(self, team_data: dict):
super().__init__(timeout=None)
self.team_data = team_data
def select_name_generation(self):
selection_menu_list = []
for _ in range(7):
name: str = helper.names.generate_name(self.team_data["co_trainer_na"], "male")
selection_menu_list.append(
discord.SelectOption(
label=name,
value=f"{name.lower()}"
)
)
for _ in range(3):
name: str = helper.names.generate_name(self.team_data["co_trainer_na"], "female")
selection_menu_list.append(
discord.SelectOption(
label=name,
value=f"{name.lower()}"
)
)
return selection_menu_list
@discord.ui.select(custom_id='select_co-trainer-name', placeholder="🧑🏽 | Co. Namen auswählen", options=select_name_generation)
async def select_callback(self, select, interaction):
embed = discord.Embed(
description=f'Willst du `{self.team_data["team_alias"]}` vor dein Name haben?')
self.team_data["co_trainer_name"] = select.values[0]
await interaction.message.edit(embed=embed, view=ClickChangeNameComfirmation(self.team_data))
The problem is that when I don't have the brackets here: options=select_name_generation I get this error:
Error 1:
TypeError: 'function' object is not iterable
when I add brackets to the function name like this: options=select_name_generation()
then I get this error:
Error 2:
SelectTrainerName.select_name_generation() missing 1 required positional argument: 'self'
As I can see the error indicates that there is missing an argument. But I can't give it the self argument because the line isn't in a function.
How can I fix this error?