def import_(message: discord.Message, module: str, attr: str=None):
""" Import the specified module. Specifying `attr` will act like `from attr import module`.
If the given attribute starts with a colon :, the name for the module will be defined as
whatever follows the colon character. If nothing follows, the last subcommand in the module
is used.
"""
try:
name = import_module(module, attr)
except ImportError:
await client.say(message, "Unable to import `{}`.".format(module))
except KeyError:
await client.say(message, "Unable to import `{}` from `{}`.".format(attr, module))
else:
# There were no errors when importing, so we add the name to our startup imports
lambda_config.data["imports"].append((module, attr))
lambda_config.save()
await client.say(message, "Imported and setup `{}` for import.".format(name))
评论列表
文章目录