【发布时间】:2021-05-17 17:30:44
【问题描述】:
我正在尝试为我的 discord.py 机器人中的命令制作一个 cog。我查看了一些教程,但似乎无法使其正常工作。我得到了错误,ModuleNotFoundError: No module named 'Cog'
main.py 文件的代码
bot.load_extension('Cog.Commands')
commands.py 文件的代码
from discord.ext import commands
class Commands(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def hello(self, ctx):
await ctx.send("Hi!")
def setup(bot):
bot.add_cog(Commands(bot))
我知道我可能遗漏了一些东西或改变了一些东西,对此我深表歉意。我怎样才能让这个工作正常,这样错误就消失了?谢谢!
【问题讨论】:
-
很可能是loloToster的回答中解释的区分大小写,或者齿轮中有错误导致齿轮加载失败。检查加载 cog 时抛出的错误
标签: python discord discord.py