If I want to split my code into multiple files, I can just write bash script like this:
cat first.py second.py third.py > run.py
python ./run.py
On the other hand, I have to add quite a bit of codes in order to use cogs.
Is there a reason/advantage to use cogs despite of this overhead?
There are a few reasons why I prefer to use cogs for my discord.py
bot, even when they only perform a few functions.
There comes a point in your bot’s development when you want to organize a collection of commands, listeners, and some state into one class. Cogs allow you to do just that.
Activating and Deactivating Specific Features: If your bot is added to multiple guilds, there is a good chance that the guild owners will want to customize which features are actually used in their guild.
Isolating Issues: In my personal experience, using cogs has made debugging my code so much easier. I just comment out the add_cog
statements until I can narrow down which contains the bug. I guess this is part of point (1), but I count it as an additional perk.
I definitely am biased towards cogs since I have been using them so much lately. I would add more items to my list (and I might continue to edit it in the future), but these are the easiest I could think of. As far as I know, cogs don't add any extra functionality to your code, but it does organize it much better. And hey, point -1, you get the cool categories when using the default help command!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With