1from discord.ext import commands
2
3class Test_Cog(commands.Cog):
4 def __init__(self, bot):
5 self.bot = bot # defining bot as global var in class
6
7 @commands.Cog.listener() # this is a decorator for events/listeners
8 async def on_ready(self):
9 print('Bot is ready!.')
10
11 @commands.command() # this is for making a command
12 async def ping(self, ctx):
13 await ctx.send(f'Pong! {round(self.bot.latency * 1000)}')
14
15def setup(bot): # a extension must have a setup function
16 bot.add_cog(Test_Cog(bot)) # adding a cog
1class Test(commands.cog):
2
3 def __init__(self, client):
4 self.client = client
5 self._last_member = None
1import os
2import discord
3from discord.ext import commands
4
5prefix = "?"
6cogs_folder="./cogs"
7
8bot = commands.Bot(command_prefix=prefix)
9
10for file in cogs_folder:
11 if file.endswith(".py"):
12 try:
13 bot.load_extension(f"cogs.{file[:-3]}")
14 print(f"Loaded: {file}")
15 except:
16 print(f"Could not load: {file}")