Academy · Lesson 5Academy · Lekcja 5

Host your bot 24/7Hostuj bota 24/7

Your bot only runs while your script runs. To keep it online when your PC is off, you host it somewhere that stays on — safely. Twój bot działa tylko wtedy, gdy działa skrypt. Aby był online, gdy komputer jest wyłączony, hostujesz go tam, gdzie coś jest zawsze włączone — bezpiecznie.

English / Polski IntermediateŚrednio zaawansowany 5 min

01 Why host?Po co hostować?

When you run python bot.py on your computer, the bot is only online while that window is open. Close it — or shut down — and the bot goes offline. Hosting means running it on a machine that stays on 24/7.

Gdy uruchamiasz python bot.py na swoim komputerze, bot jest online tylko wtedy, gdy to okno jest otwarte. Zamknij je — lub wyłącz komputer — a bot zniknie. Hosting oznacza uruchomienie go na maszynie, która działa 24/7.

02 Where to hostGdzie hostować

Common options, from simplest to most flexible:

Popularne opcje, od najprostszej do najbardziej elastycznej:

  • A bot-hosting platform — upload your code, set your token, click run.
  • A small VPS (virtual server) — full control via the command line.
  • A spare device like a Raspberry Pi left running at home.
  • Platforma do hostowania botów — wgraj kod, ustaw token, kliknij uruchom.
  • Mały VPS (serwer wirtualny) — pełna kontrola przez wiersz poleceń.
  • Zapasowe urządzenie, np. Raspberry Pi działające w domu.

Whatever you pick, the bot is just python bot.py running continuously. A process manager (or the host's "always restart" option) brings it back if it crashes.

Cokolwiek wybierzesz, bot to po prostu python bot.py działający w sposób ciągły. Menedżer procesów (lub opcja hosta „zawsze restartuj”) przywróci go po awarii.

03 Token as a secretToken jako sekret

On a host, set your token as an environment variable — never in the code you upload. Most platforms have a "Secrets" or "Variables" panel for this.

Na hoście ustaw token jako zmienną środowiskową — nigdy w kodzie, który wgrywasz. Większość platform ma do tego panel „Secrets” lub „Variables”.

bash
export DISCORD_TOKEN="your-token-here"
python bot.py

If a token ever leaks (e.g. pushed to a public repo), regenerate it immediately in the Developer Portal. The old one is compromised forever.

Jeśli token kiedykolwiek wycieknie (np. trafi do publicznego repozytorium), wygeneruj go od nowa w Portalu Deweloperskim. Stary jest skompromitowany na zawsze.

04 Pin your packagesZapisz pakiety

So the host installs the same libraries you used, write them to a requirements.txt. The host reads this file and installs everything before starting your bot.

Aby host zainstalował te same biblioteki, których użyłeś, zapisz je do requirements.txt. Host odczyta ten plik i zainstaluje wszystko przed uruchomieniem bota.

bash
python -m pip freeze > requirements.txt

05 Test yourselfSprawdź się

Q1. On a host, where does your token belong?Gdzie na hoście powinien być token?
Keep it in an environment variable / secrets panel, separate from your code.Trzymaj go w zmiennej środowiskowej / panelu sekretów, oddzielnie od kodu.
Q2. What does requirements.txt do?Do czego służy requirements.txt?
It records your dependencies so the host can recreate your environment.Zapisuje twoje zależności, by host mógł odtworzyć twoje środowisko.