Search code examples
pythondiscord.pypycord

Pycord, can't import "commands" from discord.ext


I'm trying to add slash commands to my discord bot, but when I try to add Option with discord.app vs code says Import "discord" could not be resolved Pylance(reportMissingImports), and when I run it it says ImportError: cannot import name 'commands' from 'discord.ext' (unknown location) Here is my code:

import discord
from discord.ext import commands
from discord import Option

bot = commands.Bot(command_prefix = '.')

@bot.slash_command()
async def hello(ctx, user:Option(discord.Member, 'User to say hello to', required=True, default=None)):
    await ctx.send(f'Hello {user}!')

How can I fix this?

Edit: I fixed the vscode error by just doing discord, but I still haven't fixed the ImportError

Edit 2: I fixed the ImportError by using pip install py-cord instead of pip install pycord, but there's a new error: line 3, in <module> from discord import Option ImportError: cannot import name 'Option' from 'discord'


Solution

  • You have to install the developer version of pycord (2.0.0) to get the Options property. you can install that with pip install git+https://github.com/Pycord-Development/pycord.

    You need git to do this.