Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Ground Controller Lvl 1
Message 1 of 4

Cogs problembs

Solved! Go to Solution.

Hi, do you mind is the problem here? I really don't understand. What should I do? Some solutions?

main

import discord
import os
from discord.ext import commands

client = commands.Bot(command_prefix='!')

@client.command()
async def load(ctx, extension):
client.load_extension(f'cogs.{extension}')
@client.command()
async def unload(ctx, extension):
client.unload_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')


client.run('NTMyOTMxNDA2NDMxNTE4NzIw.XVmgxw.oajuqxlcbUCfVlRXY31XqArtFuQ')



 example

import discord
from discord.ext import commands

class Example(commands.Cog):

def __init__(self, client):
self.client = client

@commands.Cog.listener()
async def on_ready(self):
print("Bot is online.")

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

 

C:\Users\Dani\PycharmProjects\BotDiscord\venv\Scripts\python.exe -m Bot.main
Traceback (most recent call last):
File "D:\Users\Dani\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "D:\Users\Dani\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Dani\PycharmProjects\BotDiscord\Bot\main.py", line 15, in <module>
for filename in os.listdir('./cogs'):
FileNotFoundError: [WinError 3] The system cannot find the path specified: './cogs'

Process finished with exit code 1

3 Replies
Solution
Commander Lvl 2
Message 2 of 4

Re: Cogs problembs

This error:

FileNotFoundError: [WinError 3] The system cannot find the path specified: './cogs'

 

is telling you that python cannot find the folder "./cogs". Here is the code which is looking for it:

for filename in os.listdir('./cogs'):

 

In python, paths are relative to the current working directory. I.e. whatever folder your Bot.main is sitting in, you need to have a "cogs" folder in there.

 

If you have absolutely no reason to have any cogs for your bot, then comment out the following lines:

 

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        client.load_extension(f'cogs.{filename[:-3]}')

and the script will stop seeking for a "cogs" folder.

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!

Ground Controller Lvl 1
Message 3 of 4

Re: Cogs problembs

Do you have another way ?
Ground Controller Lvl 1
Message 4 of 4

Re: Cogs problembs

I'm having the same issue. Couldn't figure it out yet. Cogs folder is already inside where the main bot is but when I run the code it's giving me an error saying " The system cannot find the path specified: ' ./cogs'