英文:
No context hint and false "unresolved reference" on discord.Interaction.response.send_message in PyCharm
问题
I'm using PyCharm来编写一个Discord机器人,使用discord.py。每次我使用InteractionResponse类的send_message方法时,都会收到这个IDE警告:“在'() -> InteractionResponse'中找不到引用"send_message"。在键入interaction.response.
时,也没有关于该特定方法的上下文提示。
然而,代码运行良好,如果我只是Ctrl+单击进入,我可以看到InteractionResponse类中确实有send_message方法。我希望能够摆脱IDE的警告,因为它很分散注意力。如果能获得上下文提示,那就更好了,因为该方法经常使用。理想情况下,我希望能够“告诉”IDE这个类中有这个方法。有什么建议吗?
这是会导致问题的示例代码:
import discord
async def respond_to_message(interaction: discord.Interaction):
await interaction.response.send_message("Hello world")
我也尝试了“文件->修复IDE”选项,包括无效化缓存,但没有帮助。
英文:
I'm using PyCharm to write a Discord bot with discord.py. Every time I use send_message method from the InteractionResponse class, I get this IDE warning: Cannot find reference "send_message" in '() -> InteractionResponse'
. There is also no context hint for that particular method when typing interaction.response.
However, the code is working fine and I can see that there is a send_message method in the InteractionResponse class if I just ctrl+click into it. I would love to get rid of the IDE warning, as it's distracting. Getting a context hint would be nice too, as the method is frequently used. Ideally I would love to be able to "tell" IDE that there is this method in this class. Any ideas?
This is the example code that will cause the issue:
import discord
async def respond_to_message(interaction: discord.Interaction):
await interaction.response.send_message("Hello world")
I have also tried the "File -> Repair IDE" option all the way down, Invalidate Caches included, it didn't help.
答案1
得分: 1
有几种可能的解决方法来消除IDE警告。
- 在设置中关闭
Unresolved References
检查。转到设置 -> 编辑器 -> 检查
,在Python
下有一个名为Unsolved References
的黄色警告,取消选中该选项并点击应用。优点:一键简单。缺点:以后不会再为其他代码文件显示任何未解决的引用警告。 - 添加注释以避免特定代码部分的检查。多行版本如下(以下示例将关闭
YourClass()
的未解决引用检查):
# noinspection PyUnresolvedReferences
class YourClass(...):
# 您的代码
- 添加注释以抑制单行检查:
await interaction.response.send_message(...) # noqa
英文:
There are several possible solutions to remove the IDE warning.
- Turning off
Unresolved References
inspection checking in the setting. Go tosettings -> Editor -> Inspections
, underPython
, there is a yellow warning calledUnsolved References
, uncheck the option and click apply. Pros: simple with one click. Cons: It will not show any unresolved references warning later for your other code files. - Adding comment to avoid inspection check for specific parts of code. The multiple lines version is that (the following example will turn off unresolved references check for
YourClass()
# noinspection PyUnresolvedReferences
class YourClass(...):
# Your code
- Adding comment to suppress single line inspection
await interaction.response.send_message(...) # noqa
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论