gpt4 book ai didi

python - Discord.ext.commands.errors.ExtensionNotFound : Extension 'cogs.help' could not be loaded

转载 作者:太空宇宙 更新时间:2023-11-03 20:46:21 25 4
gpt4 key购买 nike

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

我尝试了多种不同的加载齿轮的方法,但都不起作用,我尝试过使用不同的 IDE,但也不起作用。

文件夹树

enter image description here

帮助.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))

机器人.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.

最佳答案

client.load_extension(f'cogs.{filename[:-3]}')

根本无法工作,因为您正在使用 cogs.name 加载扩展程序。

应该是:

client.load_extension(f'commands.{filename[:-3]}')

关于python - Discord.ext.commands.errors.ExtensionNotFound : Extension 'cogs.help' could not be loaded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56573393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com