#Cogs seem to not load.

1 messages · Page 1 of 1 (latest)

copper condor
#

Cog file (import omitted):

class Admin(Cog):
    def __init__(self, bot: Bot) -> None:
        self.bot: Bot = bot
        self.webhooks: Dict[str, TextChannel] = {}

    @cmd.group(name="admin", pass_context=True)
    async def admin(self, ctx: Context):
        await ctx.reply("Admin cog is loaded.")

    @admin.group(name="badwords", pass_context=True)
    async def badwords(self, ctx: Context):
        pass

    @badwords.command(name="addchannels", pass_context=True)
    async def addchannels(self, ctx: Context, channels: Greedy[TextChannel]):
        self.webhooks.update(
        {channel.id: await channel.create_webhook(name=f'webhook{channel.id}') for channel in channels}
    )
        await ctx.send(f"Current channels are: {[webhook for webhook in self.webhooks.keys()]}")


    @badwords.command(name="removechannels", pass_context=True)
    async def removechannel(self, ctx: Context, channels: Greedy[TextChannel], reason: str):
        reason = reason if reason else "No reason provided."
        for channel in channels:
            await self.webhooks[channel.id].delete()
            del self.webhooks[channel.id]
        await ctx.send(f"Current channels are: {[webhook for webhook in self.webhooks.keys()]}")

def setup(bot: Bot):
    bot.add_cog(Admin(bot))

Extension loading function:

@bot.group(name="service")
async def service(ctx: Context):
    pass

@service.command(name="load")
async def load(ctx: Context, cog_name: str):
    try:
        bot.unload_extension(f"commands.{cog_name}")
    except:
        pass
    bot.load_extension(f'commands.{cog_name}')
    e = Embed(
        title=f"{cog_name} loaded.",
        color=Colour.dark_green()
    )
    await ctx.reply(embed=e)

Directory layout:

commands/
  admin.py
main.py

When I try to load the extension throughservice load admin it informs me it's been successfully loaded but when I try to invoke it I get error in console about no such command existing. What gives?

karmic owl
copper condor
karmic owl
#

hm

copper condor
#

I'm using the py-cord[speed], if that matters.

karmic owl
#

just checking, the cog shows up when you print bot.cogs?

copper condor
#

yep:
{'Admin': <commands.admin.Admin object at 0x7f4c54564410>}

karmic owl
copper condor
# karmic owl could you show the full cog file instead?
from typing import Dict

from discord.ext.commands import (
    Context,
    Cog,
    Bot
)
from discord.ext import commands as cmd
from discord import TextChannel

from discord.ext.commands import Greedy
from discord import TextChannel


class Admin(Cog):
    def __init__(self, bot: Bot) -> None:
        self.bot: Bot = bot
        self.webhooks: Dict[str, TextChannel] = {}

    @cmd.group(name="admin", pass_context=True)
    async def admin(self, ctx: Context):
        await ctx.reply("Admin cog is loaded.")

    @admin.group(name="badwords", pass_context=True)
    async def badwords(self, ctx: Context):
        pass

    @badwords.command(name="addchannels", pass_context=True)
    async def addchannels(self, ctx: Context, channels: Greedy[TextChannel]):
        self.webhooks.update(
        {channel.id: await channel.create_webhook(name=f'webhook{channel.id}') for channel in channels}
    )
        await ctx.send(f"Current channels are: {[webhook for webhook in self.webhooks.keys()]}")


    @badwords.command(name="removechannels", pass_context=True)
    async def removechannel(self, ctx: Context, channels: Greedy[TextChannel], reason: str):
        reason = reason if reason else "No reason provided."
        for channel in channels:
            await self.webhooks[channel.id].delete()
            del self.webhooks[channel.id]
        await ctx.send(f"Current channels are: {[webhook for webhook in self.webhooks.keys()]}")

def setup(bot: Bot):
    bot.add_cog(Admin(bot))
karmic owl
#

and none of those run? like not even admin?

copper condor
#

Yeah, none are working, all of them say there is no command named admin

karmic owl
#

i find it unlikely to work, but what happens if you remove pass_context=True

#

(it doesn't exist anymore, it's a leftover from v0)

copper condor
#

Thanks for help wuw