不和谐的齿轮

时间:2021-01-07 08:32:53

标签: python discord discord.py-rewrite discogs-api

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

    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))

我正在使用

向 main.py 添加齿轮
# Cogs Start

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

# Cogs End

请帮忙先谢谢

1 个答案:

答案 0 :(得分:2)

您的错误来自这一行:

class Images(commands.cog):

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

class Images(commands.Cog):