Section titled Adding your bot to a serverAdding your bot to a server

After you set up an application, you'll notice it's not in any servers yet. So, how does that work?

Before you're able to see your bot in a server, you will need to add it by using a unique invite link.

The basic version of one such link looks like this:


_10
https://discord.com/api/oauth2/authorize?client_id=123456789012345678&permissions=0&scope=bot%20applications.commands

The structure of the URL is quite simple:

  • https://discord.com/api/oauth2/authorize is Discord's standard structure for authorizing an OAuth2 application (such as your bot application) for entry to a Discord server.
  • client_id=... is to specify which application you want to authorize. You'll need to replace this part with your client's id to create a valid invite link.
  • permissions=... describes the permissions that your bot will request to be granted by default upon joining the server you are adding it to.
  • scope=bot%20applications.commands specifies that you want to add this application as a Discord bot with the ability to create slash commands.

If you get an error message saying "Bot requires a code grant", head over to your application's settings and disable the "Requires OAuth2 Code Grant" option. You shouldn't enable this option unless you know why you need to.

Warning

To create an invite link, head back to your application in the developer portal, click on your bot application, and open the OAuth2 page.

In the sidebar, you'll find the URL generator. Select the bot and applications.commands options. Once you select the bot option, a list of permissions will appear, allowing you to configure the permissions your bot needs.

Grab the link via the "Copy" button and send it in a channel in Discord. CLick on the link you just sent which should reveal this:

Bot Authorization page

Choose the server you want to add it to and click "Authorize". Congratulations! You've successfully added your bot to your Discord server.

At this point, you should have a Discord bot via create-discord-bot with your .env file populated and your Discord bot in a server. You are now ready to do what you like.