Discord.py: What are Cogs and their uses.

Discord.py assists you in creating your own Discord bot. It's fantastic and in the current rewrite you can use something called cogs to help separate out your code. For instance in my Discord bot I separate each file into a different game. This helps me keep it organized so I can find my code easier. I don't need to search through blocks of code looking for a command for a certain game.

So the above code will go in the main bot file. What it will do is load the extension into the bot. It starts out be defining what extensions it should be looking for. The one thing I was not sure of when I started is the cogs. part of the code. It's referencing a folder called cogs, and a file called FortNite.py. separate the entries by a ",", The next part is a simple loop to load all of the extensions you listed earlier.

If you're following the example you'll need to make a FortNite.py inside of a folder called cogs. You'll make it a class and add the following code. For a command inside of a cog you use @commands.command, the @commands.cooldown adds a restriction so users can't spam your bot. This one adds a limit of 1 per 5 seconds per user.

At the bottom go ahead and add your function to get the cog set up. This is the last part of getting your cog up and running. You can sort your cogs anyway you want to. For me it works best for separating out games, but you can do whatever you want to.