pycord icon indicating copy to clipboard operation
pycord copied to clipboard

Code does not run when there is a __pycache__ folder

Open pratheek78 opened this issue 5 years ago • 7 comments

Summary

The code wont run when the pycache folder is in the cogs folder.

Reproduction Steps

Run the existing code with pycord 2.0.0. The code wont run unless the pycache folder is deleted. This needs to be done everytime the code is run.

Minimal Reproducible Code

for cog in listdir(path.join(path.dirname(path.abspath(__file__)), "cogs")):
    if cog.endswith(".py"):
        client.load_extension(f"cogs.{cog[:-3]}")

    else:
        print(f'unable to load {cog[:-3]}') #loads in all the cogs in the specified folder

Expected Results

The expected result is for it to load in all the cogs, and display the message "unable to load __pycach"(last 3 characters cut off because of the code).

Actual Results

The actual result is this error message: Traceback (most recent call last): File "c:\Users\prath\Desktop\Python\Projects\discord bot\DiscordBot.py", line 32, in client.load_extension(f"cogs.{cog[:-3]}") File "C:\Python Installation\Python39\lib\site-packages\discord\ext\commands\bot.py", line 732, in load_extension self._load_from_module_spec(spec, name) File "C:\Python Installation\Python39\lib\site-packages\discord\ext\commands\bot.py", line 663, in _load_from_module_spec raise errors.ExtensionFailed(key, e) from e AttributeError: module 'discord.ext.commands.errors' has no attribute 'ExtensionFailed'

Intents

intents = discord.Intents.all()

System Information

  • Python v3.9.6-final
  • pycord v2.0.0-alpha
    • pycord pkg_resources: v0.0.1
  • aiohttp v3.7.4.post0
  • system info: Windows 10 10.0.22000

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

Additional Context

No response

pratheek78 avatar Sep 12 '21 14:09 pratheek78

Not a bug, there is something wrong with your code logic.

Dorukyum avatar Sep 12 '21 15:09 Dorukyum

it works sometimes, sometimes it doesnt. i'll check my code once

pratheek78 avatar Sep 12 '21 15:09 pratheek78

Not a bug, there is something wrong with your code logic.

It is a bug. Someone removed ExtensionFailed from commands.errors. And didn't fix it with commands.Bot.

Grace-codes avatar Sep 12 '21 15:09 Grace-codes

Oh ok

pratheek78 avatar Sep 12 '21 15:09 pratheek78

But still though, why does it work sometimes, and doesnt work at others?

pratheek78 avatar Sep 12 '21 15:09 pratheek78

Not a bug, there is something wrong with your code logic.

It is a bug. Someone removed ExtensionFailed from commands.errors. And didn't fix it with commands.Bot.

That is a known bug. I was talking about the ExtensionFailed error, not the AttributeError.

Dorukyum avatar Sep 12 '21 15:09 Dorukyum

#109 pull request fixes it.

izxxr avatar Sep 12 '21 15:09 izxxr