Getting started
Create a Discord bot token and invite link, step by step
How to create an application in the Discord Developer Portal, copy the bot token, find the client id, set intents and build the invite link with the right scopes.
Every bot needs an application in the Discord Developer Portal. That is where you get the token the bot logs in with, the client id the slash commands are registered under, and the switches for intents. This guide goes through it in order.
Create the application
- Open the Developer Portal and sign in with your Discord account.
- Click New Application, give it a name and accept the terms. The name is also the default name of the bot.
- On the General Information tab, copy the Application ID. This is the CLIENT_ID in your .env file.
Get the token
Open the Bot tab and press Reset Token. Discord shows the token once. Copy it into your .env file as DISCORD_TOKEN. If you lose it, reset it again. The token gives full control over the bot, so never post it in a chat, a screenshot or a public repository.
Switch on the intents your bot needs
On the Bot tab there are three switches under Privileged Gateway Intents: Presence, Server Members and Message Content. A bot only receives the events of the intents it asked for in its code, and the privileged ones must also be switched on here. If the bot logs in but a feature does nothing, a missing switch is the usual reason. The intents guide explains which feature needs which one.
Build the invite link
- Open OAuth2, then URL Generator.
- Tick the scopes bot and applications.commands. The second one is needed for slash commands.
- Choose the permissions the bot needs. Avoid Administrator.
- Copy the generated URL, open it, choose your server and confirm.
Find your server id
To register commands for one server while testing, you need its id. In Discord open User Settings, then Advanced and switch on Developer Mode. Then right-click the server icon and choose Copy Server ID. Put it into GUILD_ID in the .env file.
Check the setup
- The bot appears in the member list of your server, offline until you start the program.
- After npm run deploy, typing a slash in a channel shows the commands of the bot.
- After npm start, the bot shows as online and answers the commands.
If something goes wrong
- "An invalid token was provided": the token is wrong or was reset. Copy a new one.
- Commands do not appear: you did not run the deploy script, or the invite link had no applications.commands scope.
- "Missing Access" or "Missing Permissions": the bot role or the channel permissions do not allow the action.
- "Used disallowed intents": a privileged intent in the code is not switched on in the portal.