【问题标题】:quitting heroku app from within python script从 python 脚本中退出 heroku 应用程序
【发布时间】:2021-03-23 04:38:02
【问题描述】:

我有一个运行 discord.py 机器人的 Heroku 应用程序,我想发出一个远程关闭命令。如果我从bash 运行,我可以使用exit()sys.exit() 执行此操作,但这些都不能在Heroku 中工作,因为应用程序将在exit() 之后再次启动,因为它认为它崩溃了。我尝试使用os.system,但也没有用。

这是我的代码:

@bot.command()
@commands.is_owner()
async def remoteshutdown(ctx):
    await ctx.send("Shutting down")
    exit()

提前致谢

【问题讨论】:

    标签: python heroku discord discord.py sys


    【解决方案1】:

    如果您想远程关闭您的机器人,请考虑使用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

    【讨论】:

      【解决方案2】:

      使用bot.close()bot.logout()

      【讨论】:

        猜你喜欢
        • 2014-08-27
        • 2016-02-16
        • 2019-10-15
        • 2017-06-28
        • 1970-01-01
        • 2012-07-02
        • 2017-01-13
        • 2014-01-18
        • 2016-12-22
        相关资源
        最近更新 更多