#Disable Select View of own Select class

1 messages · Page 1 of 1 (latest)

calm sandal
#

Final SOLUTION:

class MySelect(discord.ui.Select):
    def __init__(self):
        # doing some init stuff
        super().__init__(placeholder="Choose", min_values=1, max_values=1, options=options)

    async def callback(self, interaction: discord.Interaction):
        self.disabled = True
        await interaction.response.edit_message(view=self.view)
        # first time callback behavior

Now the original post:

I have my own discord.ui.Select class, and I would like to disable the functionality of the Select after one selection via the callback. I can manage it like:

class MySelect(discord.ui.Select):
    def __init__(self):
        # doing some init stuff
        super().__init__(placeholder="Choose", min_values=1, max_values=1, options=options)

    async def callback(self, interaction: discord.Interaction):
        if self.disabled:
            # inform user about disabled select
            return
        self.disabled = True
        # first time callback behavior

Yet I wonder myself if there is a smoother way since the Select is still callable after I disable it in the first callback execution. I would have expected to disable the Select and then see a non clickable Select similar to modern HTML forms. But maybe I infer this disabled state kinda wrong?
Is there a way to achieve a non-clickable select or is my solution the common way to achieve a one-time clickable Select?

low adder
#

But you have to edit the message and pass the view again

#

To actually update the component and disable it

calm sandal
#

Makes a lot of sense to edit the message, yet I struggle to achieve the editing.
I get always a 404 error code (thus no message found) for the Interaction's original message, which I would like to edit. In both of the following code snippets:

async def callback(self, interaction: discord.Interaction):
    self.disabled = True
    await interaction.message.edit(view=self.view)
    # first time callback behavior
async def callback(self, interaction: discord.Interaction):
    self.disabled = True
    message = await interaction.original_response()
    await message.edit(view=self.view)
    # first time callback behavior

May you have an idea what I miss to achieve a correct edit functionality?

low adder
calm sandal
#

ah, I see. Thank you for your support!
I will write a solution to the top of my thread and then close this thread. 🙂