因此,我尝试在Discord.Py Rewrite中使用Cogs,但出现此错误消息:
"C:\Users\PC\Desktop\Code\Project 01\index.py", line 410, in <module> File "C:\Users\PC\Desktop\Code\Project 01\index.py", line 407, in <module> client.load_extention(cog) AttributeError: 'Bot' object has no attribute 'load_extention' [Finished in 1.6s with exit code 1] [shell_cmd: python -u "C:\Users\PC\Desktop\Code\Project 01\index.py"] [dir: C:\Users\PC\Desktop\Code\Project 01] [path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Users\PC\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\PC\AppData\Local\Programs\Python\Python38\;C:\ffmpeg\bin;C:\Users\PC\Desktop\heroku\bin;C:\Users\PC\AppData\Local\atom\bin;C:\Users\PC\Desktop\Microsoft VS Code\bin]
我的齿轮(admin.py):
import discord from discord.ext import commands
class Admin(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command(aliases=["announce"])
async def say1(self, ctx, *, text):
ctx.send(text)
return print("Cog Loaded")
def setup(client):
client.add_cog(Admin(client))
我的主要代码(index.py):
for cog in os.listdir("./cogs"):
if cog.endswith(".py"):
try:
cog = f"cogs.{cog.replace('.py', '')}"
client.load_extention(cog)
except Exception as e:
print(f"{cog} Can not be loaded")
raise e
有人可以帮忙吗?我也需要使用齿轮。 (我的Python版本是3.8.5,而我的Discord.Python版本是最新版本)
答案 0 :(得分:0)
我认为您输错了一些内容,应该是扩展而不是扩展
for cog in os.listdir("./cogs"):
if cog.endswith(".py"):
try:
cog = f"cogs.{cog.replace('.py', '')}"
client.load_extension(cog)
except Exception as e:
print(f"{cog} Can not be loaded")
raise e