Before you start coding, you need to create and register your bot in the Discord developer portal. You can then add this bot to your Discord-server.
Creating a new bot
To create a new application, take the steps as follows:
- Sign in to the Discord developer portal and click on "New Application" on the top right.
- Next, enter a name for the application in the pop-up and press the "Create" button.
In this example we named it "D++ Test Bot".
- Move on by click the "Bot" tab in the left-hand side of the screen. Now click the "Add Bot" button on the right and confirm that you want to add the bot to your application.
On the resulting screen, you’ll note a page with information regarding your new bot. You can edit your bot name, description, and avatar here if you want to.
In this panel, you can get your bot token. A bot token looks like this:
- Do not share this token with anybody! If you ever somehow compromise your current bot token or see your bot in danger, you can regenerate the token in the panel.
Adding the bot to your server
Once you've created your bot in the discord developer portal, you may wonder:
Where is my bot now, I can't see him on my server?!
That's because you've created a bot application, but it's not on any server right now.
So to invite the bot to your server, you must create an invitation URL.
- go again into the Applications page and click on your bot.
- Go to the "OAuth2" tab and click on the subpage "URL Generator".
- Select the "bot" scope. If your bot uses slash commands, also select "applications.commands".
You can read more about scopes and which you need for your application here.
- Choose the permissions required for your bot to function in the "Bot Permissions" section.
- For bots with elevated permissions, Discord enforces two-factor authentication on the bot owner's account when added to servers that have server-wide 2FA enabled.
- Copy and paste the resulting URL in your browser. Choose a server to invite the bot to, and click "Authorize".