discord.py cogs github code example
Example 1: discord.py cog
from discord.ext import commands
class Ping(commands.Cog):
"""Receives ping commands"""
@commands.command()
async def ping(self, ctx: commands.Context):
await ctx.send("Pong")
def setup(bot: commands.Bot):
bot.add_cog(Ping())
Example 2: discord.py cogs example
import os
import discord
from discord.ext import commands
prefix = "?"
cogs_folder="./cogs"
bot = commands.Bot(command_prefix=prefix)
for file in cogs_folder:
if file.endswith(".py"):
try:
bot.load_extension(f"cogs.{file[:-3]}")
print(f"Loaded: {file}")
except:
print(f"Could not load: {file}")