简体   繁体   中英

DIscord.py Cogs

I coded my bot in a single main.py. But when I am looking through code to change something it is impossibly hard.I tried searching and found about cogs.I am trying to organize my discord.py bot using cogs and got the following error

    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)

My Cats.py is

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

I am adding cogs to main.py using

# Cogs Start

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

# Cogs End

please help Thanks in advance

Your error comes from this line:

class Images(commands.cog):

Your class must heritate from commands.Cog , not commands.cog :

class Images(commands.Cog):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM