无法加载扩展 'commands_files/say'
Extension 'commands_files/say' could not be loaded
我正在使用以下 2 个代码,机器人不会添加齿轮,但它适用于我的其他机器人。
我的文件夹是正确的,因为它不会告诉其他错误。
主要代码:
#!/home/bist1484/virtualenv/winterlounge/3.7/bin/python3.7
import discord
from discord.ext import commands
# import subprocess
import os
import traceback
import json
import botsettings as bs
client = commands.Bot(command_prefix=".")
try:
for filename in os.listdir('./commands_files'):
if filename.endswith('.py'):
client.load_extension(f'commands_files.{filename[:-3]}')
except Exception as e:
print(e)
说齿轮:
import discord
from discord.ext import commands
import botsettings as bs
class Say(commands.Cog):
def __init__(self, client):
self.client = client
def is_staff(ctx):
if (ctx.guild.get_role(651372813436846091) in ctx.author.roles) or ctx.author.id in bs.trustedUsers:
return True
# Say command
@commands.command()
@commands.check(is_staff)
async def say(self, ctx, *, text):
if ctx.channel.id not in bs.modmailChannels:
await ctx.send(text)
await ctx.message.delete()
embed = discord.Embed(title="Special command used", color=0x6f6f6f)
embed.set_author(name="ctx.author.name", icon_url="ctx.author.avatar")
embed.add_field(name="Command used", value="{ctx.invoked_with}", inline=False)
embed.set_footer(text=f"Jump URL: {ctx.message.jump_url}")
await self.client.get_channel(bs.logsChannel).send(embed=embed)
def setup(client):
client.add_cog(Say(client))
我收到以下错误:
Extension 'commands_files/say' could not be loaded
你知道为什么会这样吗?
编辑:这是我的文件结构。注意 commands_files 必须在 cgi-bin 中,因为 start.py 文件在.
编辑 2:我成功获得了完整的回溯,就在这里。
Traceback (most recent call last):
File "/home/bist1484/virtualenv/winterlounge/3.7/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 621, in load_extension lib = importlib.import_module(name)
File "/home/bist1484/virtualenv/winterlounge/3.7/lib64/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import File "", line 983, in _find_and_load
File "", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'say' The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/bist1484/winterlounge/bot.py", line 32, in client.load_extension("say")
File "/home/bist1484/virtualenv/winterlounge/3.7/lib/python3.7/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 'say' could not be loaded.
我没有发现这有什么问题,但通过将所有文件放在与 start.py
相同的文件夹中成功地使它起作用。
我正在使用以下 2 个代码,机器人不会添加齿轮,但它适用于我的其他机器人。
我的文件夹是正确的,因为它不会告诉其他错误。
主要代码:
#!/home/bist1484/virtualenv/winterlounge/3.7/bin/python3.7
import discord
from discord.ext import commands
# import subprocess
import os
import traceback
import json
import botsettings as bs
client = commands.Bot(command_prefix=".")
try:
for filename in os.listdir('./commands_files'):
if filename.endswith('.py'):
client.load_extension(f'commands_files.{filename[:-3]}')
except Exception as e:
print(e)
说齿轮:
import discord
from discord.ext import commands
import botsettings as bs
class Say(commands.Cog):
def __init__(self, client):
self.client = client
def is_staff(ctx):
if (ctx.guild.get_role(651372813436846091) in ctx.author.roles) or ctx.author.id in bs.trustedUsers:
return True
# Say command
@commands.command()
@commands.check(is_staff)
async def say(self, ctx, *, text):
if ctx.channel.id not in bs.modmailChannels:
await ctx.send(text)
await ctx.message.delete()
embed = discord.Embed(title="Special command used", color=0x6f6f6f)
embed.set_author(name="ctx.author.name", icon_url="ctx.author.avatar")
embed.add_field(name="Command used", value="{ctx.invoked_with}", inline=False)
embed.set_footer(text=f"Jump URL: {ctx.message.jump_url}")
await self.client.get_channel(bs.logsChannel).send(embed=embed)
def setup(client):
client.add_cog(Say(client))
我收到以下错误:
Extension 'commands_files/say' could not be loaded
你知道为什么会这样吗?
编辑:这是我的文件结构。注意 commands_files 必须在 cgi-bin 中,因为 start.py 文件在.
编辑 2:我成功获得了完整的回溯,就在这里。
Traceback (most recent call last):
File "/home/bist1484/virtualenv/winterlounge/3.7/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 621, in load_extension lib = importlib.import_module(name)
File "/home/bist1484/virtualenv/winterlounge/3.7/lib64/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import File "", line 983, in _find_and_load
File "", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'say' The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/bist1484/winterlounge/bot.py", line 32, in client.load_extension("say")
File "/home/bist1484/virtualenv/winterlounge/3.7/lib/python3.7/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 'say' could not be loaded.
我没有发现这有什么问题,但通过将所有文件放在与 start.py
相同的文件夹中成功地使它起作用。