Skip to content
← Back to Community
Cogs in discord.py
Profile icon
HarshVardhan19

What are cogs?

Do you ever get frustrated trying to find the code for a command in the main.py file which already has more than 700 lines of code?
Well, Cogs are the exact things you need! Literally speaking, putting all the commands and events in the single main.py file and making it messy with more than 500 lines, is not the best coding practice.

Instead, you can create different files, with different codes and commands, and then load them to the bot!
Neat? huh?
I already wrote a basic cogs tutorial in a Repl project with all those information using comments inside the main.py file and the cogs files itself.

The basic order to go through the project, in my opinion, would be:

  1. Go through the blah.py file first.
  2. Then the foo.py file.
  3. And lastly, making use of them in the main.py file!

Go check it out!
Upvote the post, if you liked it, and also if I was able to reduce some headaches by helping you learn how to reduce the clutter in the main.py file. Feel free to leave a comment down below!
Also thank you for reading this far!

Voters
Profile icon
lxcidwyd
Profile icon
SeanDaquipil
Profile icon
MattHepburn
Profile icon
Popcorn4hire
Profile icon
PROJUDE
Profile icon
blasphemousjohn
Profile icon
CoolJames1610
Profile icon
HarshVardhan19
Comments
hotnewtop
Profile icon
CoolJames1610

Awesome!

Profile icon
HarshVardhan19

@CoolJames1610 Thank you!!

Profile icon
KateWinslet

Notwithstanding the business, an organization's composed correspondence ought to be painstakingly evolved. The nature of an association's writing is an immediate impression of its demonstrable skill.
By:
https://articleoftheweek.com/
https://s4she.com/
https://article.onl/
https://latestentertainments.com/
https://vouchercodesgo.co.uk/

Profile icon
AstOwOlfo

Just a thought, consider creating an automated cogs handler so you don't have to manually define the files in an array. Would be a big QoL improvement on the current code.

Profile icon
HarshVardhan19

@agent9002 you mean to say, an automated loader which automatically loads all the files with .py extension in a folder?
If you meant that, I didn't put it in because it would actually add complex stuff to the code and I wanted to make it as beginner friendly as possible, also, its more customizable this way, cogs can be removed when needed and added when needed.

Profile icon
AstOwOlfo

well, u could probs just explain it in a tutorial. as far as im aware, this is a standard feature of most discord bots so you could probs get a lot of clout off making it @HarshVardhan19

Profile icon
HarshVardhan19

@agent9002 okay I'll probably create another tutorial and add it soon.