Learnmonkey Learnmonkey Logo
× Warning:

The tutorial you are reading is currently a work in-progress.

Discord.py Setup

Creating a Discord Bot

To use Discord.py, we of course need a Discord bot.

First of all, make sure you are signed in to Discord by going to the website.

Then, go to the Discord applications page and click the "New Application" button, which is located left of your Discord avatar:

You should then see a form with the name of the application. You can fill in whatever you want; it doesn't matter:

Then, click on the "Bot" tab and click the "Add Bot" button:

Now, you should see bot settings. Here, you can rename bot's username and change the avatars. Make sure that the "Public Bot" switch is turned on.

Notice how there is a hidden token field in the settings. The bot token is basically the password for the bot and it is very important that you do not share the bot token. If you accidentally share your bot token, you can click the "Regenerate" button to regenerate the bot token.

Making a Server

Now, we need to make a server to test our bot in. Think of a server as a group chat but with more features.

To create a server, we first of all need to make sure we are signed into Discord. Then, we can begin using the web version of Discord. You can also download and use the desktop version of Discord.

Now, go to the left sidebar in Discord and click on the big plus sign. Then, you can follow through the form and make a server. The server name doesn't matter.

Inviting Our Bot to the Server

Now, we of course need our bot to be in the server. We can go to our bot application page and in the sidebar, click on the "OAuth2" tab. Once we click on it, we can see a subtab called "URL Generator". This is what we'll be using to generate the URL to invite our bot to our server:

Then, we can see a big box with lots of checkboxes with the label "Scopes". Check off the "bot" scope. Then, you should see a big box of permissions for our bot. Since we are only testing our bot and not actually using it, we can simply check of "Administrator" which gives the bot administrator permission:

Then, below the bot permissions, you should see your generated URL. Copy it and paste it into your browser. Then, you can select the server you just created and now, you should see your bot is in the server!

Installing Discord.py

To install Discord.py, run the following command in your command line:

pip install discord.py
If PIP doesn't work, read our Troubleshooting PIP article.

To test if your install worked, try running the following Python script:


import discord
    

If you don't get any errors, then you have corectly installed Discord.py. Great! Now, let's get coding!