Pyrogram: Command modulation like discord.py
Posted by Dull_Caregiver_6883@reddit | Python | View on Reddit | 2 comments
Hi everyone!
I’ve been working with discord.py for a while, and one of the features I really love is the dynamic command loading system (Cogs). It keeps the codebase clean and scalable by organizing commands into separate files/modules.
Now, I’ve started working with Pyrogram, and I find having all the bot’s logic in a single file quite messy. I’m looking for a way to dynamically load commands in main.py from separate files within a commands folder, similar to how Cogs work in Discord.py.
Here’s my current project structure:
project/
│
├── .venv/
├── secrets/
│ ├── .env
│ └── config.py
├── commands/
│ ├── __init__.py
│ ├── help.py
│ ├── start.py
│ ├── example.py
├── main.py
What I’m Looking For:
-
A way to dynamically discover and load all commands from the commands folder into main.py.
-
Ideally, commands should be added to the bot without modifying main.py directly.
If anyone has experience with this or can point me toward resources/examples, I’d appreciate it!
NegotiationIll7780@reddit
Perhaps https://search.app?link=https%3A%2F%2Fgithub.com%2Fpytest-dev%2Fpluggy&utm_campaign=aga&utm_source=agsadl1%2Csh%2Fx%2Fgs%2Fm2%2F4
reza2602@reddit
read the smart plugins section from official docs