def source(self, ctx, *, command: BotCommand):
"""Displays the source code for a particular command.
There is a per-user, 2 times per 5 seconds cooldown in order to prevent spam.
"""
paginator = commands.Paginator(prefix='```py')
for line in inspect.getsourcelines(command.callback)[0]:
# inspect.getsourcelines returns the lines with the newlines at the
# end. However, the paginator will add it's own newlines when joining
# up the lines. We don't want to have double lines. So we have to
# strip off the ends.
#
# Also, because we prefix each page with a code block (```), we need
# to make sure that other triple-backticks don't prematurely end the
# block.
paginator.add_line(line.rstrip().replace('`', '\u200b`'))
for p in paginator.pages:
await ctx.send(p)
# Credits to Reina
评论列表
文章目录