Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The load_extensions function is not working correctly #1177

Open
3 tasks done
BazZziliuS opened this issue Mar 25, 2024 · 1 comment · May be fixed by #796
Open
3 tasks done

The load_extensions function is not working correctly #1177

BazZziliuS opened this issue Mar 25, 2024 · 1 comment · May be fixed by #796
Labels
bug Something isn't working

Comments

@BazZziliuS
Copy link

BazZziliuS commented Mar 25, 2024

Summary

She misidentifies the audience

Reproduction Steps

image
image

Minimal Reproducible Code

# Dont work
class CenturyBOT(commands.InteractionBot):
    def __init__(self) -> None:
        super().__init__(intents=disnake.Intents.all(), owner_id=347880706724069376)
        self.load_extensions('./module')

if __name__ == "__main__":
    load_dotenv(os.path.join(os.path.dirname(__file__), 'data', '.env'))
    bot = CenturyBOT()
    bot.run(os.getenv("BOT_TOKEN"))


# Work
class CenturyBOT(commands.InteractionBot):
    def __init__(self) -> None:
        super().__init__(intents=disnake.Intents.all(), owner_id=347880706724069376)
        for filename in os.listdir('./centurybot/module'):
            if filename.endswith('.py') and filename != '__init__.py':
                self.load_extension(f'module.{filename[:-3]}')

if __name__ == "__main__":
    load_dotenv(os.path.join(os.path.dirname(__file__), 'data', '.env'))
    bot = CenturyBOT()
    bot.run(os.getenv("BOT_TOKEN"))

Expected Results

I expected cogs to run without a loop for

Actual Results

Mistake

Intents

disnake.Intents.all()

System Information

- Python v3.11.6-final
- disnake v2.9.1-final
    - disnake importlib.metadata: v2.9.1
- aiohttp v3.9.0
- system info: Windows 10 10.0.22621 AMD64

Checklist

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

Additional Context

https://discord.com/channels/808030843078836254/1220966362747244555/1221327569585176606
No response

@BazZziliuS BazZziliuS added the unconfirmed bug Something might not be working label Mar 25, 2024
@shiftinv shiftinv added bug Something isn't working and removed unconfirmed bug Something might not be working labels Mar 25, 2024
@shiftinv
Copy link
Member

This is one of the unfortunate flaws of load_extensions().

If you change the working directory from which the process is launched to ./centurybot/ instead of the top-level directory, load_extensions("module") should work, but this might break other things in your code that relied on a specific cwd.

Running your code as a module would also work, but requires you to adjust some imports.
Alternatively, the manual approach of iterating through os.listdir as you did before is perfectly fine too.

#796 aims to improve load_extensions significantly, but there are still a couple edge cases to be ironed out.

@shiftinv shiftinv linked a pull request Mar 25, 2024 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants