我试图在我的不和谐的机器人中添加斜杠命令,但是当我尝试用Option
和discord.app vs代码添加Import "discord" could not be resolved Pylance(reportMissingImports)
时,当我运行它时,它说ImportError: cannot import name 'commands' from 'discord.ext' (unknown location)
是我的代码:
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}!')
我怎么才能解决这个问题?
编辑:我只做了discord
就修复了vscode错误,但是我仍然没有修复ImportError
编辑2:我用pip install py-cord
而不是pip install pycord
修复了pip install pycord
,但是有一个新的错误:line 3, in <module> from discord import Option ImportError: cannot import name 'Option' from 'discord'
发布于 2021-12-24 06:38:24
您必须安装开发人员版本的pycord (2.0.0)才能获得Options
属性。您可以使用pip install git+https://github.com/Pycord-Development/pycord
安装它。
你需要git来做这件事。
发布于 2022-01-19 16:02:29
原因应该是您没有正确安装uncord.py/pycord。
您应该尝试重新安装模块。
对于discord.py,它是:
pip install discord
对软绳来说是:
pip install pycord
https://stackoverflow.com/questions/70469410
复制相似问题