0

我在一个 main.py 中编写了我的机器人。但是,当我查看代码来更改某些内容时,这是不可能的。我尝试搜索并找到有关 cogs。我正在尝试使用 cogs 组织我的 discord.py 机器人并收到以下错误

    Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 607, in _load_from_module_spec
    spec.loader.exec_module(lib)
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/runner/Commander/cogs/Cats.py", line 6, in <module>
    class Images(commands.cog):
TypeError: module() takes at most 2 arguments (3 given)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "main.py", line 58, in <module>
    Client.load_extension(f'cogs.Cats')
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 664, in load_extension
    self._load_from_module_spec(spec, name)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 610, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.Cats' raised an error: TypeError: module() takes at most 2 arguments (3 given)

我的 Cats.py 是

import aiohttp
import discord
import asyncio
from discord.ext import commands

class Images(commands.cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def meow(self, ctx):
        async with ctx.channel.typing():
            async with aiohttp.ClientSession() as cs:
                async with cs.get("http://aws.random.cat/meow") as r:
                    data = await r.json()

                    em = discord.Embed(title="Meow")
                    em.set_image(url=data['file'])

                    await ctx.send(embed=em)


def setup(client):
    client.add_cog(Images(client))

我正在使用将 cogs 添加到 main.py

# Cogs Start

Client.load_extension(f'cogs.tictactoe')
Client.load_extension(f'cogs.gamble')
Client.load_extension(f'cogs.Cats')

# Cogs End

请帮助提前谢谢

4

1 回答 1

2

您的错误来自这一行:

class Images(commands.cog):

您的班级必须继承自commands.Cog,而不是commands.cog

class Images(commands.Cog):
于 2021-01-07T08:39:25.963 回答