是否有可能获得协程的指导?

Is it possible to get doctring of coroutine?

我得到了一个由以下定义的函数:

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

但我会使用它的文档来提供比 discord 模块更好的功能帮助。我怎么会有文档字符串?

我试过了:

__doc__ ( inside ping function )
ping.__doc__

您可以从 the implementation of command 中看到您的 func 被包裹在一个 Command 对象中:

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

该装饰器的文档说明:

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.

您可以在 the implementation of Command 中看到这种情况,因此您应该能够通过 ping.help.

查看您的文档字符串