Skip to content

Ship

Running your bot

The code is done. What is left happens in Discord: an application, a token, the right intents and an invite. Then you start it.

All of this happens in Discord

The steps below use the Discord Developer Portal at discord.com/developers/applications with your own Discord account. SwisserAI never needs your token. The same walk-through with more detail is our Discord bot setup guide.

Create the application

Every bot needs its own application. Open the Developer Portal, press New Application at the top right and name it after the bot. That name is what members see in the member list; you can rename it later. It is free.

You are done when the left menu shows General Information, OAuth2 and Bot.

Get the token

  1. 1

    Open the Bot page

    In the left menu of your application, open Bot.

  2. 2

    Reset the token

    Press Reset Token and confirm. Discord shows the token once. Copy it straight into the place it belongs (next section). If you lose it, reset again; there is no way to look it up.

  3. 3

    Keep it secret

    The token is the password of your bot. Never paste it into Discord, a screenshot or a public GitHub repository. Discord detects tokens in public repositories and kills them within minutes.

The token is not the Application ID on General Information. Your bot needs that id as well, as the client id.

Turn on the intents it needs

On the Bot page, under Privileged Gateway Intents, are three switches. Turn on exactly the ones the README of your bot lists, then press Save Changes:

  • Message Content Intent

    reads the text of ordinary messages, for example ! commands or a word filter
  • Server Members Intent

    reacts to joins and leaves, or reads the member list
  • Presence Intent

    needs to know who is online or what they play

Slash commands and buttons need none of them. The FiveM bot in this guide uses no privileged intent, so it changes nothing here.

Invite it to your server

  1. 1

    Open the URL Generator

    In the left menu open OAuth2, then URL Generator.

  2. 2

    Tick two scopes

    Tick bot and applications.commands. Missing the second is the most common mistake of the whole setup: the bot joins and shows online, but has no slash commands.

  3. 3

    Tick the permissions

    Tick what the README lists. The FiveM bot in this guide needs View Channel, Send Messages, Connect for the status voice channel and Manage Roles to hand out the whitelist role.

Role order matters

A bot can only give or take roles that sit below its own highest role. In Server Settings, Roles, drag the bot's role above the roles it manages, such as the whitelist role.

Start it

For the ids of channels, roles and the server, turn on Developer Mode in Discord (User Settings, Advanced). Then right-click a channel, role or the server icon and choose Copy ID. Follow the tab for your target:

  1. 1

    Install Node.js

    Install Node.js 18 or newer (22 LTS is a good choice), unzip the project into a folder and open a terminal there.

  2. 2

    Install the packages

    npm install
  3. 3

    Fill in .env

    Copy .env.example to .env and fill every line: no quotes, no spaces around the value. The names differ per bot; a typical file looks like this:

    DISCORD_TOKEN=your-bot-token
    DISCORD_CLIENT_ID=the-application-id
    DISCORD_GUILD_ID=your-server-id
  4. 4

    Build, register the commands, start

    npm run build
    npm run deploy
    npm start

    npm run deploy registers the slash commands in your server; run it again after a change adds or renames a command. The bot is online while this terminal stays open.

If it does not come online, the console names the reason. The common ones are on Troubleshooting.

Keeping it online

A standalone bot holds one long connection to Discord and runs only while its process runs:

  • Your PC is fine for testing. Closing the terminal or sleeping the PC takes the bot offline.
  • A VPS or a bot host keeps it online around the clock. Run it with a process manager such as pm2, so it restarts after a crash or a reboot.
  • Free web hosting tiers that put idle apps to sleep drop bots, because a bot looks idle to them. Use a host that gives you a real machine or a real background process.
npm install -g pm2
npm run build
npm run deploy
pm2 start dist/index.js --name my-bot
pm2 save

A FiveM resource needs none of this: it is online whenever your FiveM server is. A server restart restarts the bot too.