add an event in cog discord.py 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: how to make a cog discord.py
from discord.ext import commands
class Test_Cog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print('Bot is ready!.')
@commands.command()
async def ping(self, ctx):
await ctx.send(f'Pong! {round(self.bot.latency * 1000)}')
def setup(bot):
bot.add_cog(Test_Cog(bot))