Discord Python Rewrite - Cogs Error (client.load_extention(cog) AttributeError: 'Bot' object has no attribute 'load_extention')
Discord Python Rewrite - Cogs Error (client.load_extention(cog) AttributeError: 'Bot' object has no attribute 'load_extention')
因此,我尝试在 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
有人能帮忙吗?我也需要使用 Cogs。 (我的Python版本是3.8.5,我的Discord.Python版本是最新的)
我想你打错了什么,应该是 extension 而不是 extension
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
因此,我尝试在 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
有人能帮忙吗?我也需要使用 Cogs。 (我的Python版本是3.8.5,我的Discord.Python版本是最新的)
我想你打错了什么,应该是 extension 而不是 extension
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