def source(self, command : str = None):
"""Displays my full source code or for a specific command.
To display the source code of a subcommand you have to separate it by
periods, e.g. tag.create for the create subcommand of the tag command.
"""
source_url = 'https://github.com/miraai/LunaBot'
if command is None:
await self.bot.say(source_url)
return
code_path = command.split('.')
obj = self.bot
for cmd in code_path:
try:
obj = obj.get_command(cmd)
if obj is None:
await self.bot.say('Could not find the command ' + cmd)
return
except AttributeError:
await self.bot.say('{0.name} command has no subcommands'.format(obj))
return
# since we found the command we're looking for, presumably anyway, let's
# try to access the code itself
src = obj.callback.__code__
if not obj.callback.__module__.startswith('discord'):
# not a built-in command
location = os.path.relpath(src.co_filename).replace('\\', '/')
final_url = '<{}/blob/master/{}#L{}>'.format(source_url, location, src.co_firstlineno)
else:
location = obj.callback.__module__.replace('.', '/') + '.py'
base = 'https://github.com/Rapptz/discord.py'
final_url = '<{}/blob/master/{}#L{}>'.format(base, location, src.co_firstlineno)
await self.bot.say(final_url)
评论列表
文章目录