Python: Making a Discord bot (Part 7: Cogs)

Lucas · 200K views · 2019 · 22:55

Open on YouTube

Python, Ruby & scripting languagesSoftware practice, open source & careerstutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when asking or answering how to organise a discord.py bot into cogs and set up a cog loader with load, unload and reload commands.

Recommended by 1 people across 1 different months, 2021 to 2022.

What it is

Part 7 of a Python discord.py tutorial series by Lucas, covering cogs in the rewrite version of the library. It walks through splitting bot commands into separate files and loading, unloading and reloading them as extensions.

What people said

Recommends Xueren · 2021-01 · Stack Overflow · on “Discord.py No output when using the message”

Are you loading the cog? That might be why nothing shows up, it's because you aren't actually running the code so it doesn't tell you anything. This helped me a lot when I was having the same issue: [this video] The first part with the loading and unloading might be what you need.

Cites Nucleo __ · 2021-01 · Stack Overflow · on “Are Cogs supposed to be in the same code?”

I m new to discord.py too but here i m sharing my little knowledge! [Sorry if i have some problems in my vocab!] Cogs are like subclasses that helps you to organise your code and distribute your code in different sections, but still having a single bot and not to have a very long long code with different types of commands in a single file. More Info At: Discord.py Documentation For Cogs [LINK] Create a folder named cogs in directory same as of your bot.py To load and unload cogs using command you can use this code: import discord from discord.ext import commands import os @client.command() async def load(ctx, extension): client.load_extension(f'cogs.{extension}') @client.command() async def

Cites oin · 2021-08 · Stack Overflow · on “trying to make a cogs loader doscord.py”

I am trying to make a command which will load a certain cogs from cog folder. I have followed a youtube tutorial [this video] but I am getting some errors and I don't know how to fix it import discord import os from discord.ext import commands client = commands.Bot(command_prefix= "#") @client.command() async def load(ctx, extension): client.load_extension(f'cogs.{extension}') @client.command() async def unload(ctx, extension): client.unload_extension(f"cogs.{extension}") @client.command async def reload(ctx, extension): client.reload_extension(f"cogs.{extension}") for filename in os.listdir('./cogs'): if filename.endswith('.py'): client.load_extension(f'cogs.{filename[:-3]}') client.run('token')

Cites Mahrab Hossain · 2022-01 · Stack Overflow · on “AttributeError: 'CogLoader' object has no attribute '_BotBase__extensions'”

As a part of learning OOP, I'm trying to create a class that will handle the loading and unloading cogs. However I'm getting the following error Traceback (most recent call last): File "c:\Users\mirza\Desktop\Work\Working Directory\Project\Bots\2B\bot.py", line 50, in <module> main() File "c:\Users\mirza\Desktop\Work\Working Directory\Project\Bots\2B\bot.py", line 43, in main bot = CustomBotClient() File "c:\Users\mirza\Desktop\Work\Working Directory\Project\Bots\2B\bot.py", line 21, in __init__ raise e File "c:\Users\mirza\Desktop\Work\Working Directory\Project\Bots\2B\bot.py", line 18, in __init__ self.load_extension(f"cogs.{filename[:-3]}") File "C:\Users\mirza\AppData\Local\Programs\Pyth

Cites oin · 2022-01 · Stack Overflow · on “Trying to make a cogs loader discord.py”

So basically I was trying to make a cogs loder from a youtube toutorial( [this video] )but i am getting some error and i dont know how to fix it. I am using anaconda navigator virtual environment in vscode. My anaconda navigator virtual environment name is disc This is my file import discord import os from discord.ext import commands client = commands.Bot(command_prefix= "#") @client.command() async def load(ctx, extension): client.load_extension(f'cogs.{extension}') @client.command() async def unload(ctx, extension): client.unload_extension(f"cogs.{extension}") @client.command async def reload(ctx, extension): client.reload_extension(f"cogs.{extension}") for filename in os.listdir('./cogs'): if