我正在尝试启动一个位于不同py文件中的discord.py机器人,它可以成功地让机器人启动,但是我不知道启动脚本后如何退出/停止它。如果我在shell中,ctrl+c可以工作,但是我有一个运行模块的pyqt脚本,我希望保持启动程序不关闭它。
@click.group(invoke_without_command=True, options_metavar='[options]')
@click.pass_context
@click.option('-c', '--cli', help='launch hangoutcore without a gui.', is_flag=True)
def main(ctx, cli):
"""Launches the bot."""
if ctx.invoked_subcommand is None:
# since cli is a bool we can pass it as an environment variable so it can be accessed by any code running in this session.
os.environ["bot_CLI"] = str(cli)
print(os.environ["bot_CLI"])
if not cli:
try:
qasync.run(botLauncher())
except asyncio.exceptions.CancelledError as e:
print(e)
else:
try:
hangoutcore = runpy.run_module('hangoutcore')
print(hangoutcore)
except SystemExit as exception:
exitcode = exception.code
else:
exitcode = 0发布于 2021-08-25 19:15:03
最好是重构你的hangoutcore,只有当你调用它中的某件东西时,才能做重要的事情。
import discordpy, eris, apple, fnord
# ... lots of bot logic
def run():
...然后你就可以
import hangoutcore无论何时,然后打电话
hangoutcore.run()当你想做主要事情的时候。
https://stackoverflow.com/questions/68928626
复制相似问题