从 python 脚本中退出 heroku 应用程序
quitting heroku app from within python script
我有一个 Heroku 应用 运行 一个 discord.py
机器人,我想发出远程关机命令。如果我是 bash
的 运行,我可以用 exit()
或 sys.exit()
来做到这一点,但这些在 Heroku 中都不起作用,因为应用程序将在 exit() 后再次启动,因为它认为它是一个崩溃。我尝试使用 os.system
但这也不起作用。
这是我的代码:
@bot.command()
@commands.is_owner()
async def remoteshutdown(ctx):
await ctx.send("Shutting down")
exit()
提前致谢
使用bot.close()
或bot.logout()
。
如果您想远程关闭您的机器人,请考虑使用 bot.logout()
。
将您的代码替换为:
@bot.command()
@commands.is_owner()
async def remoteshutdown(ctx):
await ctx.send("Shutting down")
# Shuts down the bot
await bot.logout()
我还建议您使用更好的托管服务,例如 LawlietHost,它们提供免费和高级托管服务。 https://discord.gg/37HuZHMzgq
我有一个 Heroku 应用 运行 一个 discord.py
机器人,我想发出远程关机命令。如果我是 bash
的 运行,我可以用 exit()
或 sys.exit()
来做到这一点,但这些在 Heroku 中都不起作用,因为应用程序将在 exit() 后再次启动,因为它认为它是一个崩溃。我尝试使用 os.system
但这也不起作用。
这是我的代码:
@bot.command()
@commands.is_owner()
async def remoteshutdown(ctx):
await ctx.send("Shutting down")
exit()
提前致谢
使用bot.close()
或bot.logout()
。
如果您想远程关闭您的机器人,请考虑使用 bot.logout()
。
将您的代码替换为:
@bot.command()
@commands.is_owner()
async def remoteshutdown(ctx):
await ctx.send("Shutting down")
# Shuts down the bot
await bot.logout()
我还建议您使用更好的托管服务,例如 LawlietHost,它们提供免费和高级托管服务。 https://discord.gg/37HuZHMzgq