Error due to import of SelectOption on disnake 2.9.1

33 Views Asked by At

I'm getting an error when running my Discord bot

disnake.ext.commands.errors.ExtensionFailed: Extension 'cogs.nabor' raised an error: ImportError: cannot import name 'SelectOption' from 'disnake.ui' (C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ui\init.py).

I'm using disnake version 2.9.1 and here's the code disnake:

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

bot = commands.Bot(command_prefix="!", help_command=None, intents=disnake.Intents.all())

class NaborCog(commands.Cog):
    def init(self, bot):
        super().init()
        self.bot = bot

    @commands.Cog.listener()
    async def on_ready(self):
        guild_id = 1186645028941070377
        channel = self.bot.get_channel(1189917039536635905)
        view = RoleSelectionView()
        questionnaire = Select(
            placeholder='Choose a question',
            options=[
                SelectOption(label='What is your name?', value='question_1'),
                SelectOption(label='How old are you?', value='question_2'),
                SelectOption(label='What is your timezone relative to MSK?', value='question_3'),
                SelectOption(label='How much can you activate?', value='question_4')
            ]
        )
        view.add_item(questionnaire)
        message = await channel.send("We are currently recruiting for the following roles. Please choose one:", view=view)
        view.message = message

class RoleSelectionView(View):
    def init(self):
        super().init()

    @Select(custom_id="select_role")
    async def select_role(self, interaction: disnake.ComponentInteraction):
        selected_role = interaction.data['values'][0]
        if selected_role == "support_role":
            role = interaction.guild.get_role(1189916786422992967)
        elif selected_role == "event_creator_role":
            role = interaction.guild.get_role(1189916922465243256)

        # Create questionnaire with questions
        questionnaire = Select(
            placeholder='Choose a question',
            options=[
                SelectOption(label='What is your name?', value='question_1'),
                SelectOption(label='How old are you?', value='question_2'),
                SelectOption(label='What is your timezone relative to MSK?', value='question_3'),
                SelectOption(label='How much can you activate?', value='question_4')
            ]
        )

        await interaction.response.send_message(
            f"You have successfully chosen the {role.name} role! Please answer the following questions:",
            components=[questionnaire]
        )
        self.stop()

def setup(bot): 
    bot.add_cog(NaborCog(bot=bot))  

             . 

I hope you can help me fix this error.

I tried using AI to fix this error and reinstalled the library but it didn't help

0

There are 0 best solutions below