0

I want to set up a latency command in a cog but it isn't possible since there's no client attribute in a cog, upon using self.client.latency it still gives a error

class misc(commands.Cog):
    def _init_(self , client):
        self.client = client

    @commands.command()
    async def ping(self, ctx):
        await ctx.send(f"Pong {round(self.client.latency * 1000)}ms")


def setup(client):
    client.add_cog(misc(client))

and the error is Command raised an exception: AttributeError: 'misc' object has no attribute 'client'

1 Answers1

2

When creating a class make sure you add two undescores in init function eg: __init__ instead of _init_.

Methods with __ are known as dunder or magic methods in python. Read these for more info on them:

Why do we use init in Python classes?

Why does Python use 'magic methods'?