#Multiple Dropdown Selections values

1 messages · Page 1 of 1 (latest)

pseudo scroll
#

When a user uses a slash command, a message including multiple select menus is sent. I'd like to access the selected values together in the sale place

So I have something like this basically as view:

class MyView(discord.ui.View):
  @discord.ui.select(...)
  async def callback_shape(self, select, interaction):
  """Returns the selected shape."""
    ...

  @discord.ui.select(...)
  async def callback_color(self, select, interaction):
  """Returns the selected color."""
    ...

The first callback gives me as value red, the second one gives me triangle
But these values are local to the callback as far as I understood

I'd like to have red and triangle available together somewhere tu use them in a query

Is that possible ?
Or do I need to think it in another way to have these informations together ?

NB: I tried to search for this keywords, and didn't find anything similar

Thank you

dreamy cloud
#

Which is referenced using self

#

Override the init and set the values to default as None

pseudo scroll
#

Hello, thanks for taking time to answer

You mean overriding it that way ?

class MyView(discord.ui.View):
  def __init__(self):
    super().__init__()
    self.values = None
pseudo scroll
#

But how the different select callbacks are going to put values there ?
Each callback has to push his own select.values[0] inside self.values ?

dreamy cloud
#

You could use smth like self.colour_choice and self.shape_choice

pseudo scroll
#

Got it! I just tried it that way, and it works as intended

dreamy cloud
#

Or you can directly access self.values[0] and self.values[1] too lol

#

It can be accessed from either callback

dreamy cloud
pseudo scroll
#

Yeah, the values are local to the callbacks, that's why I asked initially ;p

#

the complete workflow is a bit more complex that the snippet I used to describe my question, so pushing the values from the selects in an object variable of the view worked well for me

dreamy cloud
pseudo scroll
#

Yes, I need to ask the user to select informations that are really different, so I needed to use multiple Select dropdowns

#

Speaking of which, there is no possibility to dynamically fill the optionfield of a Select, right ?
to do something like this:

@discord.ui.select(
    placeholder = "Choose the OpenStack SSH Key",
    min_values = 1,
    max_values = 1,
    options = sshkey_list()
    )

And have sshkey_list to be a function, like in a slash_command option to fill it with an autocomplete list

dreamy cloud
dreamy cloud
#

.rtfm view.add

ashen raptorBOT
dreamy cloud
pseudo scroll
#

I'll have a look at that, thanks !

strange cairn
#

If that worked for you please close your thread :)

strange cairn
ashen raptorBOT
pseudo scroll
#

But as it was not the main topic here, and the advices helped me with the initial question, I will close the thread.