#self.values[x] - dropdown

1 messages · Page 1 of 1 (latest)

dawn junco
#

Hi, I have problem with my dropdown. I have 4 options, but every time i get content from first value. Why?

class Dropdown(disnake.ui.StringSelect):
    def __init__(self):
        options = [
            disnake.SelectOption(
                label="🤖 Boty Discord", description="Kliknij, aby wyświetlić cennik"
            ),
            disnake.SelectOption(
                label="🌍 Strony WWW", description="Kliknij, aby wyświetlić cennik"
            ),
            disnake.SelectOption(
                label="🎨 Grafiki", description="Kliknij, aby wyświetlić cennik"
            ),
            disnake.SelectOption(
                label="📁 Serwery Discord", description="Kliknij, aby wyświetlić cennik"
            ),
            disnake.SelectOption(
                label="🧱 Budowle Minecraft", description="Kliknij, aby wyświetlić cennik"
            ),
            disnake.SelectOption(
                label="💻 Hosting Botów", description="Kliknij, aby wyświetlić cennik"
            ),
        ]

        super().__init__(
            placeholder="💸 Wybierz Usługę!",
            min_values=1,
            max_values=1,
            options=options,
        )

    async def callback(self, inter: disnake.MessageInteraction):
        if self.values[0]:
            await inter.response.send_message(f"1")
        elif self.values[1]:
            await inter.response.send_message(f"2")
        elif self.values[2]:
            await inter.response.send_message(f"3")
        elif self.values[3]:
            await inter.response.send_message(f"4")
        elif self.values[4]:
            await inter.response.send_message(f"5")


class DropdownView(disnake.ui.View):
    def __init__(self):
        super().__init__()
        self.add_item(Dropdown())```
#

please help

errant ibex
#

self.values[0]
thats what user select

dawn junco
#

u're right

#

so what I must do?

calm heath
#

Values is a dict containing all selected values. Since you limit it to one. Only [0] is filled and contains whatever value or label for the selected option

dawn junco
calm heath
#

I suggest you add the value= to all your SelectOptions so you can easily filter on that

dawn junco
calm heath
#

Then in the callback values[0] will contain either boty, strony etc

#

So you need to do if values 0 == "boty" etc

#

Writing on mobile with gloves so excuse syntax lol

dawn junco
#

let me try

#

@calm heath you my namesake, u're best!

#

it works!

#

Thank u very much!

#

?resolve