Answers for "discord.py cog on disable"

4

how to make a cog discord.py

from discord.ext import commands

class Test_Cog(commands.Cog):
	def __init__(self, bot):
      self.bot = bot # defining bot as global var in class
      
	@commands.Cog.listener() # this is a decorator for events/listeners
    async def on_ready(self):
      print('Bot is ready!.')
      
	@commands.command() # this is for making a command
    async def ping(self, ctx):
		await ctx.send(f'Pong! {round(self.bot.latency * 1000)}')
        
def setup(bot): # a extension must have a setup function
	bot.add_cog(Test_Cog(bot)) # adding a cog
Posted by: Guest on October-12-2020
2

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())
Posted by: Guest on June-01-2021

Python Answers by Framework

Browse Popular Code Answers by Language