Last active
June 18, 2024 07:23
-
-
Save 15696/a1b10f044fbd658ce76ab1f862a1bda2 to your computer and use it in GitHub Desktop.
simple cogs example in discord.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# main.py | |
from discord.ext import commands | |
import os | |
client = commands.Bot(command_prefix = "!") | |
for f in os.listdir("./cogs"): | |
if f.endswith(".py"): | |
client.load_extension("cogs." + f[:-3]) | |
client.run("token") | |
# cogs / test.py | |
from discord.ext import commands | |
class Test(commands.Cog): | |
def __init__(self, client): | |
self.client = client # sets the client variable so we can use it in cogs | |
@commands.Cog.listener() | |
async def on_ready(self): | |
# an example event with cogs | |
@commands.command() | |
async def command(self, ctx): | |
# an example command with cogs | |
def setup(client): | |
client.add_cog(Test(client)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's what I was missing in all the official and fancy guidelines.
Thank you, sir, you are a true savior!