Skip to content

Failing to provide default values for menu select in modal crashes the interaction #3170

Description

@s0lst1ce

Summary

Failing to provide default values for menu select in modal crashes the interaction

Reproduction Steps

When you create an instance of the DesignerModal class and add_item a ui.Label on which set_select is called the default_values param must be set. Otherwise the interaction raises an exception.

Traceback:

Traceback (most recent call last):
  File "./.venv/lib/python3.13/site-packages/discord/ui/view.py", line 389, in _scheduled_task
    await item.callback(interaction)
  File "./main.py", line 88, in first_button_callback
    self.restrictions = FoodConstraint(
                        ~~~~~~~~~~~~~~^
        title="Quelles sont tes contraintes alimentaires ?"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "./main.py", line 26, in __init__
    food_choice.set_select(
    ~~~~~~~~~~~~~~~~~~~~~~^
        min_values=1,
        ^^^^^^^^^^^^^
    ...<5 lines>...
        ],
        ^^
    )
    ^
  File "./.venv/lib/python3.13/site-packages/discord/ui/label.py", line 339, in set_select
    select = Select(
        select_type=select_type,
    ...<8 lines>...
        default_values=default_values,
    )
  File "./.venv/lib/python3.13/site-packages/discord/ui/select.py", line 293, in __init__
    default_values=self._handle_default_values(default_values, select_type),
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.13/site-packages/discord/ui/select.py", line 347, in _handle_default_values
    for dv in default_values:
              ^^^^^^^^^^^^^^
TypeError: 'ellipsis' object is not iterable

Minimal Reproducible Code

import discord

class MyModal(discord.ui.DesignerModal):
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        food_choice = discord.ui.Label("question")
        food_choice.set_select(
            min_values=1,
            max_values=1,
            options=[
                discord.SelectOption(label="1"),
                discord.SelectOption(label="2"),
            ],
        )

        self.add_item(restrictions)

    async def callback(self, interaction: discord.Interaction):
        await interaction.response.defer()

Just send this modal from anywhere.

Expected Results

The docs do not mention this and I don't think it's the expected behavior considering it doesn't work like that when make a string select through another means (ex: creating a select through a decorator).

Actual Results

See above

Intents

None

System Information

- Python v3.13.2-final
- py-cord v2.7.1-final
- aiohttp v3.13.3
- system info: Linux 6.19.8-arch1-1

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions