• <i id='UaAyJ'><tr id='UaAyJ'><dt id='UaAyJ'><q id='UaAyJ'><span id='UaAyJ'><b id='UaAyJ'><form id='UaAyJ'><ins id='UaAyJ'></ins><ul id='UaAyJ'></ul><sub id='UaAyJ'></sub></form><legend id='UaAyJ'></legend><bdo id='UaAyJ'><pre id='UaAyJ'><center id='UaAyJ'></center></pre></bdo></b><th id='UaAyJ'></th></span></q></dt></tr></i><div id='UaAyJ'><tfoot id='UaAyJ'></tfoot><dl id='UaAyJ'><fieldset id='UaAyJ'></fieldset></dl></div>
      <bdo id='UaAyJ'></bdo><ul id='UaAyJ'></ul>

        <small id='UaAyJ'></small><noframes id='UaAyJ'>

        <legend id='UaAyJ'><style id='UaAyJ'><dir id='UaAyJ'><q id='UaAyJ'></q></dir></style></legend>
        <tfoot id='UaAyJ'></tfoot>

        ModuleNotFoundError:没有名为“cogs"的模块

        时间:2023-10-11

        • <legend id='ZXaHo'><style id='ZXaHo'><dir id='ZXaHo'><q id='ZXaHo'></q></dir></style></legend>

              <bdo id='ZXaHo'></bdo><ul id='ZXaHo'></ul>
              <tfoot id='ZXaHo'></tfoot>
            • <small id='ZXaHo'></small><noframes id='ZXaHo'>

                  <tbody id='ZXaHo'></tbody>

                  <i id='ZXaHo'><tr id='ZXaHo'><dt id='ZXaHo'><q id='ZXaHo'><span id='ZXaHo'><b id='ZXaHo'><form id='ZXaHo'><ins id='ZXaHo'></ins><ul id='ZXaHo'></ul><sub id='ZXaHo'></sub></form><legend id='ZXaHo'></legend><bdo id='ZXaHo'><pre id='ZXaHo'><center id='ZXaHo'></center></pre></bdo></b><th id='ZXaHo'></th></span></q></dt></tr></i><div id='ZXaHo'><tfoot id='ZXaHo'></tfoot><dl id='ZXaHo'><fieldset id='ZXaHo'></fieldset></dl></div>
                1. 本文介绍了ModuleNotFoundError:没有名为“cogs"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我编写了一个使用 cogs 的不和谐机器人.这是我在每个扩展程序/cog 中加载的代码:

                  I wrote a discord bot that uses cogs. Here's my code for loading in each extension/cog:

                  import discord
                  import os
                  from discord.ext import commands
                  
                  client = commands.Bot(command_prefix= '.')
                  
                  @client.command()
                  async def load(ctx, extension):
                      client.load_extension(f'cogs.{extension}')
                  
                  @client.command()
                  async def unload(ctx, extension):
                      client.unload_extension(f'cogs.{extension}')
                  
                  @client.command()
                  async def reload(ctx, extension):
                      client.unload_extension(f'cogs.{extension}')
                      client.load_extension(f'cogs.{extension}')
                  
                  for filename in os.listdir('.Cogs'):
                      if filename.endswith('.py'):
                          client.load_extension(f'cogs.{filename[:-3]}')
                  
                  client.run('token')
                  

                  我收到以下错误:

                  Traceback (most recent call last):
                    File "C:/Users/indap/PycharmProjects/untitled1/venv/Include/Main.py", line 22, in <module>
                      client.load_extension(f'cogs.{filename[:-3]}')
                    File "C:UsersindapAppDataLocalProgramsPythonPython38libsite-packagesdiscordextcommandsot.py", line 649, in load_extension
                      spec = importlib.util.find_spec(name)
                    File "C:UsersindapAppDataLocalProgramsPythonPython38libimportlibutil.py", line 94, in find_spec
                      parent = __import__(parent_name, fromlist=['__path__'])
                  ModuleNotFoundError: No module named 'cogs'
                  

                  我检查过,文件路径是正确的,我什至尝试使用不同的文件路径,但我仍然得到同样的错误.

                  I've checked, the file path is correct, and I even tried using different file path but I still get the same error.

                  推荐答案

                  看起来可能是区分大小写的问题.在遍历目录的内容时,您已经编写了 .Cogs 作为路径,但在 load_extension() 方法中,您已经编写了 cogs..

                  It looks like it might be a case-sensitive issue. When iterating over the directory's contents, you have written .Cogs as the path, but in the load_extension() method, you have written cogs..

                  尝试将其更改为 Cogs..要么,要么将目录本身全部重命名为cogs.

                  Try changing it to Cogs. instead. Either that, or rename the directory itself all lower-case to cogs.

                  这篇关于ModuleNotFoundError:没有名为“cogs"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 discord.py 中设置可选参数? 下一篇:discord.py - 自动更改角色颜色

                  相关文章

                  最新文章

                  <i id='YhPlq'><tr id='YhPlq'><dt id='YhPlq'><q id='YhPlq'><span id='YhPlq'><b id='YhPlq'><form id='YhPlq'><ins id='YhPlq'></ins><ul id='YhPlq'></ul><sub id='YhPlq'></sub></form><legend id='YhPlq'></legend><bdo id='YhPlq'><pre id='YhPlq'><center id='YhPlq'></center></pre></bdo></b><th id='YhPlq'></th></span></q></dt></tr></i><div id='YhPlq'><tfoot id='YhPlq'></tfoot><dl id='YhPlq'><fieldset id='YhPlq'></fieldset></dl></div>
                  <tfoot id='YhPlq'></tfoot>
                  • <bdo id='YhPlq'></bdo><ul id='YhPlq'></ul>

                  1. <legend id='YhPlq'><style id='YhPlq'><dir id='YhPlq'><q id='YhPlq'></q></dir></style></legend>
                    1. <small id='YhPlq'></small><noframes id='YhPlq'>