1

I have a Heroku app running a discord.py bot and I want to make a remote shutdown command. If I was running from bash i could just do this with exit() or sys.exit() but neither of these work in Heroku as the app will startup again after the exit() because it thinks its a crash. I tried to use os.system but that didn't work either.

Here is my code:

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

Thanks in advance

Tanuj KS
  • 155
  • 2
  • 14

2 Answers2

2

Use bot.close() or bot.logout().

hayk4
  • 51
  • 2
1

If you want to remotely shutdown your bot consider using bot.logout(). Replace your code with this:

@bot.command()
@commands.is_owner()
async def remoteshutdown(ctx):
    await ctx.send("Shutting down")
    # Shuts down the bot
    await bot.logout()

I would also recommend that you use a better hosting service like LawlietHost, they provide both free and premium hosting. https://discord.gg/37HuZHMzgq

Mysterious K
  • 79
  • 2
  • 8