Search code examples
pythondiscord.pydocstring

Is it possible to get doctring of coroutine?


I got a function defined by:

@bot.command()
async def ping(ctx):
    """
        return pong
    """
    await ctx.send("pong !")

But I would take its doctring to make a better function help than the discord module. How could I have docstring?

I tried:

__doc__ ( inside ping function )
ping.__doc__

Solution

  • You can see from the implementation of command that your func is wrapped in a Command object:

    def command(name=None, cls=None, **attrs):
        """..."""
        if cls is None:
            cls = Command
    
        def decorator(func):
            if isinstance(func, Command):
                raise TypeError('Callback is already a command.')
            return cls(func, name=name, **attrs)
    
        return decorator
    

    The docstring of that decorator states that:

    By default the help attribute is received automatically from the docstring of the function and is cleaned up with the use of inspect.cleandoc. If the docstring is bytes, then it is decoded into str using utf-8 encoding.

    You can see this happen in the implementation of Command, so you should be able to see your docstring via ping.help.