Bots & Apps: code, environment variables and start
How your Discord, Telegram or Twitch bot or small app gets onto the server: from a Git repository or by upload, with tokens in the environment variables and a start command the portal usually finds by itself.
Your bot server has two tabs of its own: App for runtime, code and start, and Environment for tokens and other settings. Every change counts from the next start; after saving, Restart now is right beside it.
Getting the code onto the server
Under App, choose at Code where it comes from:
- Git repository
- Enter the https address, such as https://github.com/name/bot, and the branch if needed (empty: the repository's default branch). The code is fetched at the next start. The first fetch replaces files of the same name with the repository's; all other files stay.
- Upload
- Upload your files in the Files tab or over SFTP (Access tab). An archive such as .zip or .tar.gz unpacks in the file manager.
With Update at every start, the server fetches the newest code before every start. Files of the repository that you changed on the server are never overwritten: if the repository has a new version of one too, the code as it was starts and the console says so. With the switch off, fetch the new code on the Overview with Update and restart.
A private repository
Create a token with read access at your Git host, on GitHub for example a fine-grained token that may read only this repository with “Contents: Read”.
Under App, at Access token, press Set token, paste it and save.
Restart the server.
The token is stored encrypted, sent only to the repository's server and never shown again; you can replace or remove it. It is neither in the address nor in the Git settings or the server's environment: at a start from the customer area it is there encrypted, used only to fetch the code, and deleted before dependencies are installed or your program starts. When the server restarts by itself after a crash, it does not fetch the code of a private repository again. Anyone who may edit files could still change the start, so use a token that may read only this one repository. When the address later points to another Git host, the token is removed.
Environment variables
Tokens and settings belong in the Environment tab, not in the code. Your program gets them at start as its environment, for example process.env.DISCORD_TOKEN in Node.js or os.environ["DISCORD_TOKEN"] in Python. dotenv libraries keep working, even without a .env file.
- Add variable adds a line; write names in capitals.
- Paste .env takes the contents of your .env file into the list. Names like TOKEN, SECRET or PASSWORD are marked secret on the way.
- A secret value is never shown again, not to you either, and never written to a log; you can only replace it.
- Save stores the whole list. The activity log names the variables, never their values.
- Anyone you share the server with who may edit files or change the start can run code of their own that reads the values. Give these rights only to people you trust with your tokens.
Also write a .env file is only for programs that read nothing but a file. The file then holds all values in plain text, is readable for anyone with file rights and is in every backup.
Dependencies
With Install dependencies at start on, the server installs what your code needs before the start, and only when the list or the version changed:
- Node.js
npm ciwith a package-lock.json, otherwisenpm install; pnpm with a pnpm-lock.yaml, Yarn with a yarn.lock.- Bun
bun install.- Python
pip install -r requirements.txtinto an environment of its own (.venv) in the server folder.- Go
go build, the program goes to .gf-app/app.- Java
- nothing: a .jar file brings its dependencies along.
The start command
Under Start command, Automatic is chosen to begin with. The server then starts:
- Node.js:
npm startwhen package.json has a start script, otherwise the file named in main, otherwise index.js, main.js, bot.js or app.js. - Bun:
bun run startor the file named in main, otherwise index.ts or index.js. - Python: main.py, bot.py, app.py or run.py.
- Java: app.jar or the only .jar file in the main folder.
- Go: the program built with
go build.
Below are the start files found in the code; a click picks one. With Own start line you enter a whole line, such as node dist/bot.js --prod. Which line ran last is on the Overview under Started with.
A port for webhooks
Every bot server has a port. Your program finds it in the environment variable PORT and must listen on 0.0.0.0; the public address is under App at Port. A bot that only connects out, to Discord or to Telegram with polling for example, does not need it. More ports come with some plans under Network.
Related articles
- Bot does not start or crashesWhat the overview and the console say about a bot that does not start, ends or crashes, and the most common reasons: a missing token, the wrong start file, dependencies and too little memory.
- Change the runtime and version of a bot serverA newer version of the same runtime is one click under App. For another runtime, from Node.js to Python for example, there is Change runtime: at the same price, with a choice of what becomes of your files.
- Files and SFTPEdit, upload and extract files in the browser, or go straight onto the server over SFTP with FileZilla, WinSCP or Cyberduck.
Need help?
If this guide does not answer your question, write to us. Usually within 24 hours.