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
Open the Bot page
In the left menu of your application, open Bot.
- 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
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 filterServer Members Intent
reacts to joins and leaves, or reads the member listPresence 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
Open the URL Generator
In the left menu open OAuth2, then URL Generator.
- 2
Tick two scopes
Tick
botandapplications.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
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.
- 4
Open the link and pick the server
Open the generated URL, choose your server and authorize. The bot now sits in the member list, offline. That is correct: nothing runs it yet.
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
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
Install the packages
npm install - 3
Fill in .env
Copy
.env.exampleto.envand 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
Build, register the commands, start
npm run build npm run deploy npm startnpm run deployregisters 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.
- 1
Create the resource folder
Create a folder in your server's
resourcesdirectory, lowercase without spaces, and unzip into it. Check thatfxmanifest.luaanddist/server.jsare directly inside. - 2
Make sure yarn runs
The resource installs discord.js through the
yarnresource, which ships with the default server data. It must be present and start before your bot. - 3
Add the settings to server.cfg
FiveM has no
.env. Settings aresetlines inserver.cfg, above theensureline. The README names them; for the bot in this guide they are:set discord_bot_token "BOT_TOKEN_FROM_DISCORD_DEVELOPER_PORTAL" set discord_client_id "APPLICATION_CLIENT_ID" set discord_guild_id "DISCORD_SERVER_ID" set discord_whitelist_role_id "WHITELIST_ROLE_ID" set discord_staff_channel_id "STAFF_CHANNEL_ID" set discord_status_channel_id "STATUS_VOICE_CHANNEL_ID" set fivem_max_players "64" set discord_apply_invite_url "https://discord.gg/your-server" ensure status-whitelist-bot- 1. server.cfg lines: the settings this bot reads
The name after
ensuremust be your folder name. The README may suggest another one; any name works as long as the folder and theensureline match. - 4
Restart and watch the console
Restart the server and watch the server console, not Discord. The bot logs a line with the resource name when it is ready and when it has registered its commands. There is no
npm run deployfor a resource.
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 saveA FiveM resource needs none of this: it is online whenever your FiveM server is. A server restart restarts the bot too.