Square CloudSquare Cloud

How to add a bot to your Discord server

To add a bot to your server, open its invite link, pick the server and authorize the permissions it asks for. You need the Manage Server permission there, and the bot only shows online while its process is running.

Updated 8 min read

Learning objectives

After reading this article you will be able to:

  • Generate the invite link with the right scopes and permissions
  • Choose between installing the app to a server or to a user
  • Understand why the bot shows offline and fix invite errors
On this page

A bot doesn't join a Discord server through a regular invite, the kind you send to friends. Someone with permission in the server has to open the bot's authorization link (an OAuth2 URL), pick the server and approve the permissions it requests. That holds for a ready-made bot you found online and for the bot you wrote yourself.

This guide shows how to generate that link in the Developer Portal, which permissions to ask for, the difference between a server install and a user install, and why the bot shows offline right after it joins. If you haven't created the app and its token yet, start with how to make your first Discord bot.

What do you need to add a bot?#

  • The Manage Server permission in the target server, as the discord.js guide points out. Owners and administrators already have it. Without it, the server doesn't even show up in the invite's list.
  • The bot's invite link. Ready-made bots usually publish it on their website or in Discord's app directory. For your own bot, you generate it in the Developer Portal.
  • For your own bot, the Public Bot setting on the Bot tab. Unchecked, only you can add the bot to servers. Checked, anyone with the link and the right permissions in a server can, according to the OAuth2 docs.

There are two paths, and both produce the same authorization URL.

From the Installation tab. With the Install Link set to Discord Provided Link, Discord gives you a short link that uses the Default Install Settings on the same page. That link only takes the bot and applications.commands scopes, according to the application docs.

  1. Under Installation Contexts, make sure Guild Install is checked. By default, new apps only support installation to servers.
  2. Under Default Install Settings, on the Guild Install row, add the applications.commands and bot scopes.
  3. Pick the permissions (next section), save and copy the link.

From the URL generator. On the OAuth2 tab, the OAuth2 URL Generator builds the URL on the spot:

  1. Check bot and applications.commands. Checking bot reveals the permission list.
  2. Check the permissions the bot uses.
  3. Copy the generated URL, open it in your browser, pick the server and authorize.

The bot scope puts the bot user in the selected server. applications.commands lets the app create commands in that server; the scopes table says it comes included by default with bot, and checking both keeps the invite explicit.

Which permissions should the bot ask for?#

Ask only for what its commands use. Each permission is a bit, and the URL carries the sum as one integer in the permissions parameter. A bot that reads channels, replies and sends embeds needs three, with the values from the permissions docs:

Permission in the Developer Portal Bit Value
View Channels 1 << 10 1024
Send Messages 1 << 11 2048
Embed Links 1 << 14 16384
Total 19456

A music bot adds Connect and Speak. A moderation bot adds only the actions it actually performs. Avoid Administrator: it grants every permission and bypasses channel restrictions, and a leaked token with it gives whoever holds it control of the server.

Invite permissions aren't permanent. An administrator can change what the bot does by editing the server's roles, with no new invite. Role hierarchy also applies: the bot can only sort and edit roles below its own highest role, and it can only grant permissions it has itself. For a bot that assigns roles, drag its role above the roles it will hand out.

The format is:

text
https://discord.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=bot%20applications.commands&permissions=19456

To get the sum right, compute it with discord.js (invite.js, with "type": "module" in package.json):

js
import { PermissionsBitField } from "discord.js";

const permissions = new PermissionsBitField([
  PermissionsBitField.Flags.ViewChannel,
  PermissionsBitField.Flags.SendMessages,
  PermissionsBitField.Flags.EmbedLinks,
]);

const scope = encodeURIComponent("bot applications.commands");
console.log(
  `https://discord.com/oauth2/authorize?client_id=${process.env.CLIENT_ID}&scope=${scope}&permissions=${permissions.bitfield}`,
);

Run it with CLIENT_ID=your_id node invite.js. CLIENT_ID is the Application ID on the General Information tab. The other accepted parameters, all in the OAuth2 docs:

  • guild_id: pre-selects a server in the list.
  • disable_guild_select=true: stops the user from changing the pre-selected server.
  • integration_type: 0 installs to a server and 1 installs to the user; it only applies when scope includes applications.commands.

A URL with only client_id (optionally with permissions, guild_id or disable_guild_select) uses the Portal's Default Install Settings. Passing scope or integration_type overrides those defaults.

Server install or user install?#

An app can support two installation contexts, which you check on the Installation tab:

  • Guild Install. The bot joins as a member, receives that server's events according to its intents and offers its commands to members. Whoever installs it needs Manage Server.
  • User Install. The app is tied to the installing account, and its commands follow that person across servers and DMs. It asks for no server permission, but the app never becomes a member: it isn't in the member list and gets none of the server's events. In a server where the app isn't installed, the Use External Apps permission decides whether replies are public; when it's off, only the person who ran the command sees the reply.

To work in a user install, a command has to be global and declare where it runs:

js
import {
  ApplicationIntegrationType,
  InteractionContextType,
  SlashCommandBuilder,
} from "discord.js";

export const ping = new SlashCommandBuilder()
  .setName("ping")
  .setDescription("Replies with Pong!")
  .setIntegrationTypes(
    ApplicationIntegrationType.GuildInstall,
    ApplicationIntegrationType.UserInstall,
  )
  .setContexts(
    InteractionContextType.Guild,
    InteractionContextType.BotDM,
    InteractionContextType.PrivateChannel,
  );

The application commands docs note that these fields only apply to global commands and that PrivateChannel (DMs and group DMs) only makes sense for user-installed apps. If you add a new context later, update and re-register the commands you already have.

Why does the bot show offline after you add it?#

The invite gives the bot a place in the server, not a running program. The bot shows online while its process is connected to the Gateway, the WebSocket connection that delivers events; when the bot closes that connection, the Gateway docs say it will appear offline. That's why it sits grey in the member list until you start the code.

If the code is running and the bot is still offline, the usual causes are a wrong or reset token, a privileged intent requested in code but not enabled in the Portal, and a process that crashed without you noticing. Each one is diagnosed in why a Discord bot goes offline and Discord bot intents errors.

One special case: apps that receive interactions over HTTP, through an Interactions Endpoint URL, answer commands without the Gateway, since the two ways of receiving interactions are mutually exclusive according to the interactions overview. An app like that can work and show offline at the same time; the two models are compared in HTTP interactions vs Gateway.

For the bot to stay online without your computer, its process has to run on a machine that never sleeps. See how to keep a bot online 24/7.

What errors show up when adding a bot?#

  • The server isn't in the invite's list. Your account lacks Manage Server there. Ask an administrator for the role, or send them the link.
  • Integration requires code grant. Requires OAuth2 Code Grant is on in the Bot tab. Turn it off unless you run a full OAuth2 flow with a redirect.
  • Someone else can't add your bot. Public Bot is unchecked, so only the account that owns the app can add it.
  • The bot joined, but its commands don't show. Almost always the commands were never registered with the API, a separate step from the invite. Commands registered both per server and globally can also show up twice. The steps are in how to create slash commands.
  • DiscordAPIError[50013]: Missing Permissions. Code 50013 means the bot lacks permission for that action, per the status codes table: the permission is missing from the invite or the role, a channel overrides it, or the target sits above the bot's role.
  • The bot stops joining new servers at 100. Discord requires verification for an app to grow past 100 servers. It lives on the App Verification tab of the Portal and includes confirming the app owner's identity.

How to do this on Square Cloud#

The invite always happens on Discord; what hosting fixes is the offline bot. On Square Cloud, the bot runs in an isolated, always-on container, so it shows online as soon as the process connects to the Gateway and stays that way after you shut down your computer. You deploy it by ZIP upload in the dashboard, the CLI, GitHub or the VS Code extension, with discord.js, discord.py, JDA, Discord.Net or any other Gateway library.

  1. Upload the project without .env and without node_modules; for a Node.js bot, the platform runs npm install at start. The squarecloud.app file is optional: the dashboard generates it with the runtime, memory and main file.
  2. Set DISCORD_TOKEN in the application's environment variables. The change applies on the next restart.
  3. Follow the real-time logs until the bot reports it's online, then check for the green status in your server.

Automatic restart, on by default for dashboard deploys, brings the process back when it exits with an error. Each bot uses at least 256 MB from the plan's RAM pool, and Hobby, at R$12.49 per month, includes 1 GB of RAM and 1 vCPU. See the details in Discord bot hosting.

Bot hosting

Keep your bot online 24/7 with automatic restarts

Discord bot hosting

FAQs

Who can add a bot to a Discord server?

Anyone with the Manage Server permission in it, which includes the owner and administrators. If Public Bot is unchecked in the Developer Portal, only the account that owns the app can add it.

Why did the bot join the server but show as offline?

The invite only gives the bot a place in the server. It shows online while its program is running and connected to the Discord Gateway, so you have to start the code on a machine that stays on.

Does the bot need the Administrator permission?

Almost never. Ask only for the permissions its commands use, such as View Channels and Send Messages. Administrator grants everything and bypasses channel restrictions, so a leaked token would hand over the whole server.

What is the difference between a server install and a user install?

Installed to a server, the bot becomes a member and receives that server's events. Installed to a user, the commands follow the installing account everywhere, but the app never joins the server as a member.

Next articleHow to create slash commands for your Discord botSlash commands are registered with the Discord API and answered within 3 seconds. Learn global and guild registration, options, autocomplete and permissions.