Docs · Running your bot

Running several bots on one server

All docs

One plan can run several bots. Your main bot stays in the top folder, as it is now, and every other bot gets a folder of its own inside bots. They share the plan's memory and processor, so a handful of small bots fit on Flurry.

Add a bot

  1. In Files, create a folder called bots in the top folder, then a folder inside it for the bot, for example bots/tickets. Letters, numbers, dots, dashes and underscores only.
  2. Upload that bot's files into its folder, with its bot.py or index.js at the top of the folder (not in another folder inside it).
  3. In the same folder, create a file called .env with the bot's token:
    BOT_TOKEN=the token of this bot
    Use a different bot's token from the one in Startup. Two bots logging in with one token keep knocking each other offline.
  4. Press Restart. The console shows [tickets] in front of everything that bot prints.

The top folder does not need a bot of its own. If it has none, only the bots in bots run.

Every bot on a server uses the language the server is set to (Startup > Docker Image): a Python server runs Python bots, a Node.js server JavaScript bots.

A bot's .env

Everything in a bot's .env reaches that bot as an environment variable, so os.environ["DB_HOST"] or process.env.DB_HOST work without loading the file yourself (loading it with dotenv as well does no harm). A few names also change how the bot is run, the same settings Startup has for the main bot:

  • BOT_TOKEN: the token. DISCORD_TOKEN works too, for bots that expect that name.
  • BOT_FILE: what to start, if it is not found by itself. Same choices as Bot file.
  • GIT_REPO, GIT_BRANCH, GIT_TOKEN: deploy this bot from its own repository into its folder. AUTO_UPDATE=0 stops it pulling on every restart. See Git deploy.
  • CRASH_WEBHOOK: a Discord webhook for this bot's crash alerts. Without one, the server's alert from Startup is used.
  • ENABLED=false: leave this bot switched off. Renaming its folder to start with _ does the same.

Packages

requirements.txt or package.json in a bot's folder install when they change, like the main bot's. Each Python bot gets a separate environment, so two bots can use different versions of the same package.

When a bot stops

The other bots keep running. The one that stopped is explained in the console and started again after 5 seconds, then after longer waits if it keeps stopping straight away. After 5 stops in a row, each within a minute of starting, it is left stopped until you fix it. Crash alerts name the bot.

The server itself stays online throughout, so Wings never marks it as crashed. The email we send when a bot has been down for hours is for servers running one bot.

Console commands

With bots in bots, the console understands:

  • bots: which bots are running, and for how long.
  • bots restart tickets, bots stop tickets, bots start tickets: one bot, without touching the others.
  • @tickets some text: send a line to that bot's input. Anything else you type goes to the main bot.

Memory and limits

  • Up to 10 bots in bots, plus the main bot.
  • All of them share the plan's memory. Node.js and Java bots each get an equal part of the memory for their heap, so one leaking bot runs out of room before it can take the others down.
  • If the server runs out of memory altogether, the plan is too small for the bots on it. How much RAM a bot needs.

Something here wrong or out of date? Tell us and it gets fixed.