【发布时间】:2022-01-05 21:17:03
【问题描述】:
我的 cogs 在 nextcord.py 上不起作用
我有这样的错误:
help cannot be loaded. [Extension 'help' could not be loaded.]
Moderation cannot be loaded. [Extension 'Moderation' could not be loaded.]
other cannot be loaded. [Extension 'other' could not be loaded.]
cogs.help cannot be loaded. [Extension 'cogs.help' could not be loaded.]
cogs.Moderation cannot be loaded. [Extension 'cogs.Moderation' could not be loaded.]
cogs.other cannot be loaded. [Extension 'cogs.other' could not be loaded.]
另外,我的代码如下所示:
@bot.command()
async def load(ctx, extensions):
if ctx.author.id == 606433100150472704:
bot.load_extension(f'cogs.{extensions}')
await ctx.send("Cogs is loaded...")
else:
await ctx.send("Вы не являетесь разработчиком...")
@bot.command()
async def unload(ctx, extensions):
if ctx.author.id == 606433100150472704:
bot.unload_extension(f'cogs.{extensions}')
await ctx.send("Cogs is unloaded...")
else:
await ctx.send("Вы не являетесь разработчиком...")
@bot.command()
async def reload(ctx, extensions):
if ctx.author.id == 606433100150472704:
bot.unload_extension(f'cogs.{extensions}')
bot.load_extension(f'cogs.{extensions}')
await ctx.send("Cogs is unloaded...")
else:
await ctx.send("Вы не являетесь разработчиком...")
initial_extensions = [
'help',
'Moderation',
'other'
]
for filename in os.listdir('./сogs'):
if filename.endswith('.py'):
initial_extensions.append(f"cogs.{filename[:-3]}") #Загрузка всех когов
if __name__ == '__main__':
for extension in initial_extensions:
try:
bot.load_extension(extension)
except Exception as error:
print('{} cannot be loaded. [{}]'.format(extension, error))
我认为问题出在代码的最后几行。当我尝试删除 if name == 'main' 一段代码时,机器人开始工作但命令不起作用。
【问题讨论】:
-
删除以下代码
except Exception as error: print('{} cannot be loaded. [{}]'.format(extension, error))并提供您的错误。 -
``` 文件“c:\Users\Andriyko\Desktop\Ghost bot\ghost.py”,第 55 行,在
bot.load_extension(extension) 文件“C:\Users\ Andriyko\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\bot.py",第 731 行,在 load_extension 中引发错误。ExtensionNotFound(name) nextcord.ext.commands.errors.ExtensionNotFound : 无法加载扩展“帮助”。 ```
标签: discord discord.py bots nextcord