discord.ext.command.errors.ExtensionFailed:扩展"cogs.fun"引发错误:缩进错误:预期缩进块(fun.py,第 7 行)



当我尝试制作齿轮时(请记住,我是新手(,我得到了错误

discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.fun' raised an error: IndentationError: expected an indented block (fun.py, line 7)

cog的代码是;

import discord
import os
from discord.ext import commands
class Fun(commands.Cog):
def setup(bot):
bot.add_cog(Example(bot))
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print('Cog is up!')
@commands.command
async def ping(ctx):
await ctx.send(f'Pong! {round(bot.latency * 1000)}ms')

好吧,我找到了答案,你需要在所有的齿轮中放置一个设置模块。如果你不这样做,如果你想在机器人启动时加载所有内容,它会给你错误。

问题似乎是setup()函数在Fun类内部,而它应该在外部,以便可以调用它。所以在你的情况下,它看起来像:

import os  
import discord  
from discord.ext import commands
class Fun(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print('Cog is up!')
def setup(bot):
bot.add_cog(Fun(bot))

相关内容

最新更新