Disnake | The message is not displayed after selecting an option in the selection menu

68 Views Asked by At

An ephemeral message is not displayed after selecting an option from the Select-Menu

Source-Code:

import disnake
from disnake.ext import commands
from disnake.ui import View, Select

class RulesCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def rules(self, ctx):
        embed = disnake.Embed(
            title="Rules",
            description="Please follow the rules below:",
            color=disnake.Color.blue()
        )

        embed.add_field(name="Rule 1", value="The first rule")
        embed.add_field(name="Rule 2", value="The second Rule")
        embed.add_field(name="Rule 3", value="The third rule")

        options = [
            disnake.SelectOption(label="Option 1", description="The first option"),
            disnake.SelectOption(label="Option 2", description="The second option"),
            disnake.SelectOption(label="Option 3", description="The third option")
        ]

        select = disnake.ui.Select(
            placeholder="Select an option",
            options=options,
            custom_id="select" 
        )

        view = disnake.ui.View()
        view.add_item(select)

        await ctx.send(embed=embed, view=view)

    @commands.Cog.listener()
    async def on_select_option(self, interaction: disnake.MessageInteraction):
        if interaction.component.custom_id == "select":
            selected_option = interaction.component.selected_options[0]
            await interaction.response.send_message(f"You have chosen: {selected_option.label}")
            await interaction.message.edit(view=None)


def setup(bot):
    bot.add_cog(RulesCog(bot))

In theory, an ephemeral message should be displayed after selecting the option, but discord writes "Interaction error".

0

There are 0 best solutions below