How host a python bot / Comment héberger un bot python

Bonjour,

J’aimerai héberger un bot Discord, python donc, sur mon serveur. Est-ce qu’il existe une app pour faire exécuter une app python en continu ? Je ne me charge nullement du développement du bot, juste de l’héberger, si c’est possible.


Hello,
I want to host a Discord (Python) bot on my server. Is there an application to continuously run a python app?
I didn’t develop the bot, I just want to host it, if possible.

Hello,

No, there is no such app at the moment. Good thing YunoHost is not the jealous type, you can install that kind of script on your own without it interfering with the server.

What I advise you to do:

  1. create a dedicated user and its directory for the script: sudo useradd -d /opt/bot_discord -m
  2. use sudo nano /opt/bot_discord/bot_discord.py or whatever to put your script in the directory. The first line should be #!/usr/bin/env python3 or something equivalent for the system to know which version of python to use.
  3. sudo chmod 550 /opt/bot_discord/bot_discord.py and sudo chown bot_discord:bot_discord -R /opt/bot_discord to secure the file
  4. create a service file with sudo nano /etc/systemd/system/bot_discord.service. Example taken from our good old YunoMDNS service:
[Unit]
Description=Discord bot
Wants=network-online.target
After=network-online.target

[Service]
User=bot_discord
Group=bot_discord
Type=simple
WorkingDirectory=/opt/bot_discord
Environment=PYTHONUNBUFFERED=1
ExecStart=/opt/bot_discord/bot_discord.py
Restart=on-failure
StandardOutput=journal

[Install]
WantedBy=default.target

(PYTHONUNBUFFERED=1 is required to make the script verbose while it runs, helpful for debugging)

  1. Refresh the daemon list with sudo systemctl daemon-reload
  2. You can even integrate it in your YunoHost panel: sudo yunohost service add bot_discord
  3. Start it from the webadmin and hope for the best :crossed_fingers:
2 Likes

Thank you for this detailled protocol! It seems doable with my little tech-background.
I will try it in the next few days.