Ask coding questions

← Back to all posts
How can I make a discordpy bot update/restart itself without stopping the Flask server
SpaceFire (115)

I want to make a command something like [prefix]restart so that my bot doesn't go offline with every little update I make.

CodeLongAndPros (1535)

If you are in the repl, Press Ctrl-Enter. Fast restart and virtually 0 downtime. (1-2 seconds)

JoshuaGottfried (1)

Make a command only you can use called restart. Then use await client/bot.logout... If you are hosting using repl it will automatically restart

SpaceFire (115)

@JoshuaGottfried this does log my bot out which is half the job but does not reactivate it

JoshuaGottfried (1)

@SpaceFire Hmmmmmm. Could you send me the code via Discord? Nuggets#0001

Codemonkey51 (923)

i have an idea run a flask server in one tread: make repl run on start and have that start which makes a flask server then runs it in a thred then start and have the restart command use os.system('python') and then on the newline exit()
so the restart command would look ike this:

import os

# -- rest of code--
#restart command

so then the thread is always running but the bot can restart itself

CodeLongAndPros (1535)

@Codemonkey51 That would cause recursion.

Not a fork bomb, but nested copy's.

leon332157 (217)

Just make 2 different threads one handles the bot restart another one handles the bot itself.

adl212 (152)

I actually don't think this is possible.