【问题标题】:VSCode doesn't show code suggestions for discord.pyVSCode 不显示 discord.py 的代码建议
【发布时间】:2019-06-29 11:26:31
【问题描述】:

我已经安装了 discord.py rewrite 并尝试使用 vscode 进行编码,但智能感知无法使用它。使用 numpy 或基本 python 模块时它工作得很好,但它不适用于 discord.py。

@client.event
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return
    message. # this shows no suggestions aside from other words in the code

这是

【问题讨论】:

  • 我是 stackoverflow 的新手,所以如果你要投反对票,请给我留言说明原因。谢谢!
  • 如果你找到答案,请告诉我。
  • @AnchithAcharya 不幸的是,我从来没有找到过,因此我放弃了这个项目。如果您找到解决方案,也请告诉我。
  • 我还没有找到解决方案,但是有一个有趣的观察。自动完成功能确实有效,只是并非无处不在。例如,当我键入消息时。它什么也没有显示,但如果我输入不和谐。或客户。它显示了很多建议。这些建议的描述似乎与 discord.py 文档中的描述完全相同。我是 python 新手,但知道 c/c++。我计划仅使用我对后者的了解,并在自动完成建议的帮助下制作一个机器人。但我想我现在必须求助于 youtube 教程。

标签: python visual-studio-code intellisense discord discord.py


【解决方案1】:

您需要告诉 Intellisense 消息参数的类型,以便它可以自动完成。

您可以通过执行以下操作来做到这一点
async def on_message(message:Type):

【讨论】:

  • async def on_message(message:discord.Message): 似乎没有修复它,async def on_message(message:discord.message.Message): 也没有
  • 对我来说,async def on_message(message: discord.Message): 工作
【解决方案2】:

老问题,但有解决方案。使用 discord 上的 Pylance 扩展程序,您可以告诉它 discord.py 的下载位置,它会识别它。

在你的工作目录中确保你有一个设置文件

working_directory
└───.vscode
│   |   settings.json

然后在该文件中包含一个键/值对,如下所示:

一般示例

{
    "python.analysis.extraPaths": ["Path/To/Folder/Containing/Dicord/Python/Code"]
}

Windows 示例

{
    "python.analysis.extraPaths": ["C:\\Users\\YOURUSERNAME\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python38\\site-packages"]
}

当你运行pip install -U discord时,它会告诉你安装文件夹在哪里

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-18
    • 2021-09-30
    • 2021-05-29
    • 2021-10-20
    • 2021-02-05
    • 1970-01-01
    • 2022-11-16
    • 2022-10-04
    相关资源
    最近更新 更多