#Cogs not loading

1 messages · Page 1 of 1 (latest)

sharp meteor
#

im getting this weird error
not even an error just a bug
cogs rn't loading

# Load cogs
for foldername in os.listdir('./cogs'):
    for filename in os.listdir(f'cogs/{foldername}'):
        if filename.endswith('.py'):
            bot.load_extension(f'cogs.{foldername}.{filename[:-3]}')```
 isn't loading anything!
but when i use the /load command, the bot seems to load the files.
the same code seems to be working in my other bots

Here's my file structure-
gleaming monolith
#

Why in the first for loop you use./cogs but the second you use cogs...

Also where is your load cogs code in the main file?

sharp meteor
#

i had forgotten def setup() before in my cogs

#

but even after adding them it aint working

hearty wigeon
round grail
#

if you're on 2.0.0, you can just load the entire folder with a simple bot.load_extension('cogs', recursive=True)

#

then you can avoid all the directory listing complexities

round grail
#

gonna have to explain a bit more than that

#

what doesn't work

sharp meteor
#

cogs rn't loading either way

#

there doesn't seem anything wrong in it

#

i have the on ready cogs listener to print if it has loaded, but nothing really loads

#

also i hope you remember i have made folders inside of cogs which have files in them

#

i tried removing the files from their seperate folders and adding them to simply cogs, but this doesn't seem to work either.. I can't seem to catch the bug

sharp meteor
#

the commands load works and loadsthe cogs

#

I think its an issue in the cogs fles.

sharp meteor
# gleaming monolith Why in the first for loop you use`./cogs` but the second you use `cogs...` Also...
import discord
import json
import os

# Get configuration.json
with open("configuration.json", "r") as config: 
    data = json.load(config)
    token = data["token"]
    owner_id = data["owner_id"]

# Intents
intents = discord.Intents.all()
# The bot
bot = discord.Bot(intents = intents, owner_id = owner_id)
# Load cogs
bot.load_extension('cogs.profile', recursive=True)
bot.load_extension('cogs.shop', recursive=True)


@bot.slash_command()
async def load(ctx, name):
    if ctx.author.id != int(owner_id):
        return
    bot.load_extension(f'cogs.{name}')
    await ctx.respond(f'Loaded {name}')
    
@bot.slash_command()
async def unloaded(ctx, name):
    if ctx.author.id != int(owner_id):
        return
    bot.unload_extension(f'cogs.{name}')
    await ctx.respond(f'Unloaded {name}')
    
@bot.slash_command()
async def reload(ctx, name):
    if ctx.author.id != int(owner_id):
        return
    bot.unload_extension(f'cogs.{name}')
    bot.load_extension(f'cogs.{name}')
    await ctx.respond(f'Reloaded {name}')


@bot.event
async def on_ready():
    print(f"We have logged in as {bot.user}")
    print(f"Discord Version: {discord.__version__}")
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name = "/help"))

# Run the bot
bot.run(token)```
#

right after creating the bot var

gleaming monolith
#

do you have the setup function in your cogs?

#
def setup(bot):
    bot.add_cog(CogName(bot))
#

also set the bot presence in the bot constructer
bot = discord.Bot(activity=...
doing any API calls in on_ready is a bad idea

sharp meteor
#

ok so basically i yeeted a file off another bot of mine and it is getting loaded, the other two files which were originally written by me AREN'T

gleaming monolith
#

try commenting out

@commands.Cog.listener()
    async def on_ready(self):
        print(f"{self.__class__.__name__} Cog has been loaded")

Its the only thing that looks a tiny bit strange

sharp meteor
#

it's actualy there so i know that the cog is loaded

#

and this exact function which i copied from the file being loaded is pasted into my other 2 files

gleaming monolith
#

ok thna it is fine.

sharp meteor
#

and it is printing cog loaded hence I know that these 2 have some weird issue in them

gleaming monolith
#

Can you show a picture of your file structure?

sharp meteor
#

scroll up

gleaming monolith
#

Oops, my bad.

What folder did your drop the cog from your other bot in?

sharp meteor
#

lemme show

#

that's the folder -- authors

gleaming monolith
#

and you ran the code bot.load_extension('cogs.authors', recursive=True)
to get it to work i assume

gleaming monolith
#

wait than how is it loaded

sharp meteor
#
for foldername in os.listdir('./cogs'):
    for filename in os.listdir(f'cogs/{foldername}'):
        if filename.endswith('.py'):
            bot.load_extension(f'cogs.{foldername}.{filename[:-3]}')```
#

same way the others wer.

gleaming monolith
#

try replacing all of your load cogs code with
bot.load_extension('./cogs', recursive=True)

sharp meteor
#

how would that work

#

that won't work lmao

#

but ok

#

I'm telling you the error is in one of the files.

gleaming monolith
sharp meteor
#

it's an issue with the cogs files

#

ima try rewrite them

gleaming monolith
#

Im not sure but the inconsistenices between ./cogs and cogs in your load files concerns me.

sharp meteor
#

let me remove te ./

#

nah it ain't working wtf

#

i rewrote the whole file it aint working

#

this is some bs

#

OK I GOT IT

#

I MADE IT WORK WTF

gleaming monolith
#

ohh!

#

what did you change?

sharp meteor
#

I just removed all the commands inside those files-

#

and it worked-

gleaming monolith
#

when you add back the commands does it break again?

sharp meteor
#

yep it is breaking on adding a command-

gleaming monolith
#

Can you try to narrow it down to a specific command?

sharp meteor
#

wait

#

i just added a test comand

#

and it still aint working

#

but wait

#

nope it aint working

#

ok i changed some things and it works @gleaming monolith

#

nicee

gleaming monolith
#

what did you change?

sharp meteor
#

i made discord.slash_command() to commands.slash_command

#

it still didnt work

#

then i copied the same thing from my other file and it worked

#

ahhhhh thers some issue

#

when i write my actual command it isnt working

#

ill fix it

#

the Option class is stopping it from working @gleaming monolith

#

that's the issue

#

without Option in the parameters, it works just fine

#

but with it added, it is an issue

#

idk y tho

gleaming monolith
#

are you on 2.0.0 and not 2.0.0bX or 2.0.0rc1?

sharp meteor
#

2.0.0

#

now even a normal command isn't working. great.

#

i sorted everything out lmao

gleaming monolith
shadow brookBOT
#

cogs/profile/profile.py line 44

async def profile(self, ctx, member : Option(discord.member, required=False)=None):```
gleaming monolith
#

So its fixed now?

sharp meteor
sharp meteor