I’m developing a Discord bot that presents a form to users and generates a dropdown based on their entries. The flow is this: the user fills out a form, I handle their input to retrieve data from an API (which typically returns a maximum of 20 items), and then I aim to display a selection menu with those options.
However, I keep encountering this error:
for player in raid_members['name']]
^^^^^^^^^^^^^
NameError: name 'raid_members' is not defined
Here is my current code:
class DataInput(discord.ui.Modal, title="Enter Details"):
user_input = discord.ui.TextInput(label="Code")
async def on_submit(self, interaction: discord.Interaction):
input_value = self.user_input.value
token = fetch_auth_token()
save_token(token)
parsed_data = api_handler.get_player_data(input_value)
global raid_members
raid_members = parsed_data['playerList']
for player in raid_members:
print(player)
await interaction.response.send_message(view=PlayerSelector())
class PlayerSelector(discord.ui.View):
@discord.ui.select(
placeholder="Pick a player",
min_values=0, max_values=20,
options=[discord.SelectOption
(label=player['name'], value=player['name'])
for player in raid_members['name']]
)
async def select_player(self, interaction: discord.Interaction, select: discord.ui.Select):
chosen_values = select.values
print(chosen_values)
await interaction.response.send_message(chosen_values)
I have tried utilizing global variables, but it still doesn’t resolve the problem. The variable appears to be undefined when the selection menu attempts to access it. How can I rectify this issue?