Lazo Lab Sign up

App 8: Build a Discord Bot / Build a Discord bot

Lesson 10 of 10

Keep it running

A bot only works while its program runs. Run it on an always-on machine like a home server with a systemd service, the same way Lazo Lab runs.

Key points

  • systemd restarts it if it crashes
  • Store the token in the service's environment
  • Check logs with journalctl
[Service]
WorkingDirectory=/home/you/bot
Environment=DISCORD_TOKEN=...
ExecStart=/home/you/bot/venv/bin/python bot.py
Restart=always

Your turn

Run your bot as a service on an always-on computer.

Watch a video on thisOpens YouTube search results for “Keep it running” in a new tab

Quiz · +10 XP

Why use systemd for a bot?

Log in to save progress and earn XP.