In this guide I'll show how to create a script that will restart the bot automatically. This script restarts your bot when it crashes. You can even make a command to restart your bot with this script.
Linux
- Go into your bot folder with :
cd BotFolderLocation
- Use
nano start.sh
to create a file calledstart.sh
and start editing. - Paste the code below :
# /bin/sh
while true
do
echo Starting Bot
node bot.js
echo Restarting Bot in 5 Seconds...
sleep 5
done
- Press CTRL+C then Y and ENTER to save the start.sh file.
- Use
chmod 777 start.sh
to give the file executable permission. - Done! Now you can start your bot by executing that file with :
./start.sh
Tutorial Video (Click on image to watch it)
Windows
- Create a file with
.bat
extension. - Paste the code below and save it.
@echo off
echo Starting..
:main
node bot.js
echo Restarting Bot..
goto main
- Done! Now you can run your bot just executing that file.
Tutorial Video (Click to watch it)
Restart Command
Use this guide to create restart command. That command actually stops the bot process but if you run your bot with the scripts above, the bot will stop and the script will start it again.