Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.74k stars 3.75k forks source link

[discordpy v2] In discord.Select, options that are defined as "default" are not present in Select.values If the user does not change the selected options #7284

Closed AiroPi closed 2 years ago

AiroPi commented 3 years ago

Summary

When you create a UI.Select, with default values, and try to retrieve the selected values with Select.values, the list is empty.

Reproduction Steps

When creating a Select list with a validation button :

class CustomView(ui.View):
    def __init__(self, bot: MyBot) -> None:
        super().__init__()
        self.bot = bot

    @ui.select(options=[discord.SelectOption(label='Français', value='fr', emoji='🇫🇷', default=True),
                        discord.SelectOption(label='English', value='en', emoji='🇺🇸', default=True)],
               max_values=2)
    async def callback(self, *_) -> None: ...

    @ui.button(label="Validate", row=1)
    async def validate(self, button, inter: discord.Interaction) -> None:
        print(self.children[0].values)  # Show [], but should show ['fr', 'en'] because they are selected by default

Minimal Reproducible Code

No response

Expected Results

self.children[0].values should show the default selected values.

Actual Results

self.children[0].values show an empty list.

Intents

all

System Information

Checklist

Additional Context

No response

AkshuAgarwal commented 3 years ago

Something similar for me too. The selected values is an empty list during initialization and if I'm not wrong it don't get updated if we don't edit the Select and just try to get those values. So maybe, we can just manually append default values into the list.

image

I also made a PR (#7286) which fixed the issue for me.