discord.ext.commands.errors.ExtensionNotFound:无法加载扩展名'cogs.help'

时间:2019-06-13 04:30:37

标签: python python-3.x discord discord.py-rewrite

我正在尝试将我的机器人的所有命令都转移到齿轮上,以使处理和排序更加容易。我无法加载齿轮。

我尝试了多种装载齿轮的方法,但都没有成功,我尝试使用也不起作用的不同IDE。

文件夹树

enter image description here

help.py

class Help(commands.Cog):

    def __init__(self, client):
        self.client = client

    @commands.command()
    async def help(self, ctx):
        # Code #


def setup(client):
    client.add_cog(Help(client))

bot.py

if __name__ == '__main__':
    for filename in os.listdir('./commands'):
        if filename.endswith('.py'):
            client.load_extension(f'cogs.{filename[:-3]}')

错误

  File "C:\Users\Tyler\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\bot.py", line 617, in load_extension
    lib = importlib.import_module(name)
  File "C:\Users\Tyler\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'cogs'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Tyler\Desktop\Seep\bot.py", line 33, in <module>
    client.load_extension(f'cogs.{filename[:-3]}')
  File "C:\Users\Tyler\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\ext\commands\bot.py", line 619, in load_extension
    raise errors.ExtensionNotFound(name, e) from e
discord.ext.commands.errors.ExtensionNotFound: Extension 'cogs.help' could not be loaded.

2 个答案:

答案 0 :(得分:0)

我很确定Discord.py引发此错误的原因是,在错误之前,它指出cogs不是有效的模块,因此无法加载齿轮。

我有同样的错误,当我评论导入语句时,它起作用了。

答案 1 :(得分:0)

我遇到了这个问题,我通过通过python而不是discord.py显式加载模块来查看脚本本身是否存在错误来解决此问题,因为Discord.py在运行时会隐藏这些错误。

> python
> help("wlct.cogs.common") <- the module you're trying to load here
problem in wlct.cogs.common - ModuleNotFoundError: No module named 'urllib.requests' 

我更新了urllib.requests-> urllib.request(我自己输入)后,问题就消失了。