'Discord.py Button, Select, View error import

I want to create a command that generates the select menu but it generates an import error

import discord
import datetime
from discord.ui import Select, View
from discord.ext import commands

client = commands.Bot(command_prefix = '.', help_command=None)

@client.command()
async def hello(ctx):
    select = Select(options=[
        discord.SelectOption(label="Hello", emoji= "✌️", description="Hello")
        discord.SelectOption(label="Hello1", emoji= "👍", description="Hello2")
        ])
    view = View()
    view.add_item(select)
    await ctx.send("Select", view= view)

error:

Traceback (most recent call last):
  File "c:\Users\bicco\Desktop\Coding\leiaraiel_bot\main.py", line 4, in <module>
    from discord.ui import Select, View
ImportError: cannot import name 'Select' from 'discord.ui' (unknown location)


Solution 1:[1]

  • Update to discord 2.0 using:
pip install discord==2.0

If you are using replit to host your code it will show you an error as replit is still not compatible with discord 2.0. Instead, you can go to the shell terminal of replit and do the following:

pip uninstall discord.py # or pip uninstall discord
  • Wait for some time until replit asks for confirmation and type y to confirm the removal.
  • Then install it like this:
pip install git+https://github.com/Rapptz/discord.py

PREVIEW

Hope it helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RiveN