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

discord.ext.commands.errors.ExtensionNotFound: Extension 'cogs.random' could not be loaded

我正在尝试 运行 我的带有命令扩展的 discord 机器人,这样我就可以将所有命令单独存储在 commands 文件夹下,但是每次我想 运行 机器人,我在终端中收到一堆错误,这里是所有内容:

航站楼: ./bot.py

Traceback (most recent call last):
  File "/home/xinto/.local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 621, in load_extension
    lib = importlib.import_module(name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'cogs.random'

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

Traceback (most recent call last):
  File "handlerbot.py", line 36, in <module>
    client.load_extension(f'cogs.{filename[:-3]}')
  File "/home/xinto/.local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 623, in load_extension
    raise errors.ExtensionNotFound(name, e) from e
discord.ext.commands.errors.ExtensionNotFound: Extension 'cogs.random' could not be loaded.

bot.py:

#!/usr/bin/python3.6

import discord
from dotenv import load_dotenv
import random
from discord.ext import commands
import os

load_dotenv()
TOKEN = os.getenv('TOKEN')

client = commands.Bot(command_prefix = '!')

#this script types "Connected!" in terminal if nothing has gone wrong    
@client.event
async def on_ready():
    print('Connected!')        

#this script makes sure that bot doesn't reply to itself
@client.event
async def on_message(message):
    if message.author == client.user:
        return

@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}')

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

client.run(TOKEN)

random.py:

import discord
import os
from discord.ext import commands

class random(commands.Cog):

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

    @commands.command()
    async def random(self, ctx):
        for filename in os.listdir(./images):
        list = '1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg'
        await ctx.send('take this', file=discord.File(random.choice(list)))

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

我不能责怪 random.py,因为它对我的其他命令也有同样的作用,我已经检查了代码,但找不到它不工作的任何原因。任何帮助将不胜感激,谢谢!

好的,我明白了。我不得不重命名 f'cogs{extension}f'commands{extension}

如果有人有同样的问题,你必须用你有命令的文件夹名称重命名 cogs,即对于我的情况,它被命名为 commands,希望我能帮助别人