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
1# bot file
2import os
3from discord.ext import commands
4
5bot = commands.Bot(command_prefix='.')
6# I am assuming that you have a test.py cog in a cogs folder
7bot.load_extension('cogs.test') # this is good but you can make it better
8
9for filename in os.listdir('./cogs'):
10 if filename.endswith('.py'):
11 bot.load_extension(f'cogs.{filename[:-3]}')
12
13 else:
14 print(f'Unable to load {filename[:-3]}')
15
16bot.run(token)