这个问题我已经反复搜索过,但一直没有找到解决方案。我通过 cmd 提示符安装了 discord.py 模块,命令如下:
py -3 -m pip install -U discord.py
再次运行它,会显示依赖项已满足的消息。我在命令提示符中检查了 pip 版本和 python 版本(以查看它们的安装位置)以及 VS Code 终端,它们都确认 Python 版本为 3.13.3。
跑步:
> python
>>> help
>>> modules
输出模块列表,包括和discord
之间的模块。运行输出结果如下:dis
doctest
help> discord
Help on package discord:
NAME
discord
DESCRIPTION
Discord API Wrapper
~~~~~~~~~~~~~~~~~~~
A basic wrapper for the Discord API.
:copyright: (c) 2015-present Rapptz
:license: MIT, see LICENSE for more details.
PACKAGE CONTENTS
(a comprehensive list of all the modules, I've checked)
SUBMODULES
async_
sync
DATA
__annotations__ = {'version_info': <class 'discord.VersionInfo'>}
__copyright__ = 'Copyright 2015-present Rapptz'
__license__ = 'MIT'
__title__ = 'discord'
version_info = VersionInfo(major=2, minor=5, micro=2, releaselevel='fi...
VERSION
2.5.2
AUTHOR
Rapptz
FILE
c:\users\MYUSER\appdata\local\programs\python\python313\lib\site-packages\discord\__init__.py
跑步> pip show discord.py
或> pip3 show discord.py
两者吐出:
Name: discord.py
Version: 2.5.2
Summary: A Python wrapper for the Discord API
Home-page:
Author: Rapptz
Author-email:
License: The MIT License (MIT)
Copyright (c) 2015-present Rapptz
(large portion of legal text ommitted for ease of reading)
Location: C:\Users\MYUSER\AppData\Local\Programs\Python\Python313\Lib\site-packages
Requires: aiohttp, audioop-lts
Required-by:
我确实尝试了所有我认为可行的方法。但无论如何,我创建的任何 .py 文件都会用黄色下划线标出出现错误的discord
行: 。通过 VS Code 运行 python 文件会抛出以下错误:import discord
Import "discord" could not be resolvedPylance(reportMissingImports)
Traceback (most recent call last):
File "c:\Users\MYUSER\OneDrive\Documents\FOLDER_NAME\FOLDER_NAME\FILENAME.py", line 1, in <module>
import discord
ModuleNotFoundError: No module named 'discord'
如果有人能提供任何关于如何解决这个问题的建议,我将不胜感激。提前致谢!
编辑:要添加 IDE 的屏幕截图, 我显然无法嵌入,所以在这里