Question

always keep active the database managed by my discord bot (discord.py)

I have noticed that when I do after days my bot commands that force my database activation failed it does not connect until I restart the bot. I would like to have the bot always active without reboots with the managed database always connected. how can I do?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

There are a few ways to do that, the one that I would recommend is to use a service like

  • First update your APT repositories:
sudo apt update
  • Then install supervisor:
sudo apt install supervisor
  • After that create a new configuration file:
sudo nano /etc/supervisor/conf.d/discord.conf
  • And add the following content:
[program:yourproject]
directory=/home/your_username/bot/
command=/usr/bin/python /home/your_username/bot/discord.py
user=root
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stderr_logfile=/var/log/discord.err.log
stdout_logfile=/var/log/discord.out.log

For more information about supervisord make sure to check out this tutorial here:

https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-supervisor-on-ubuntu-and-debian-vps

Hope that this helps! Regards, Bobby