To run pip install discord.py on Windows, use py -3 -m pip install -U discord.py; on macOS and Linux, use python3 -m pip install -U discord.py. You need Python 3.8 or newer, and it is best to install into a virtual environment so the bot's packages stay separate from the rest of your system.
The package name on PyPI is discord.py, but in code you write import discord. As of the PyPI page checked for this article (November 2026), the latest release is 2.7.1.
The install commands
These are the commands from the official installation page. The -U flag upgrades the library if an older copy is already installed.
| System | Command |
|---|---|
| Windows | py -3 -m pip install -U discord.py |
| macOS and Linux | python3 -m pip install -U discord.py |
| Inside an activated virtual environment | pip install -U discord.py |
Running pip as python -m pip (or py -3 -m pip) guarantees that the package lands in the same Python you will run the script with. Plain pip may belong to a different installation. If Python itself is not set up yet, see how to install Python on Windows first.
Use a virtual environment
A virtual environment is a folder that holds its own copy of the packages for one project. The official page suggests this sequence. Replace your-bot-source with your project folder.
cd your-bot-source
python3 -m venv bot-env
Then activate it. On macOS and Linux:
source bot-env/bin/activate
On Windows in Command Prompt:
bot-env\Scripts\activate.bat
Now install inside the environment:
pip install -U discord.py
One detail from the documentation catches many Windows users: commands run with py -3 ignore an active virtual environment, because -3 selects the global scope. Once the environment is active, use plain pip and python, not py -3. If you want an exact version instead of the latest, the guide to installing a specific pip package version covers the == syntax.
Install voice support only if you need it
For a bot that plays audio in voice channels, install the voice extra:
python3 -m pip install -U "discord.py[voice]"
PyPI lists this form with quotes, and the quotes matter. Shells such as zsh treat square brackets as a pattern, so an unquoted discord.py[voice] can fail with a "no matches found" error before pip even starts. The extra adds PyNaCl. On Linux, the installation page also lists system packages for voice support: libffi, libnacl and python3-dev. On Debian-based systems:
apt install libffi-dev libnacl-dev python3-dev
Check that the install worked
Ask Python to import the library and print its version:
python3 -c "import discord; print(discord.__version__)"
On Windows outside a virtual environment, use py -3 in place of python3. If it prints a version number such as 2.7.1, the install is fine. Example output:
2.7.1
A minimal bot to test it
This short script is an example based on the quickstart's approach: default intents, the message content intent switched on, a Client, and two event handlers. It reads the token from an environment variable named DISCORD_TOKEN instead of storing it in the file.
import os
import discord
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f"Logged in as {client.user}")
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("$hello"):
await message.channel.send("Hello!")
client.run(os.environ["DISCORD_TOKEN"])
Save it as, for example, example_bot.py. The quickstart warns: "Make sure not to name it discord.py as that'll conflict with the library." Start it with py -3 example_bot.py on Windows or python3 example_bot.py elsewhere (or just python example_bot.py inside an active virtual environment). You get the token from your bot's page in the Discord Developer Portal; the quickstart points to its "Creating a Bot Account" section for the steps.
Fixing common errors
ModuleNotFoundError: No module named 'discord'
Python cannot find the library in the interpreter that runs your script. The usual reasons are that pip installed it into a different Python, or that a virtual environment is not active. Install and run with the same interpreter: python3 -m pip install -U discord.py, then python3 your_script.py. In an editor such as VS Code, also check that the selected interpreter is the one from your bot-env folder.
A second cause is a file in your project named discord.py, or a folder named discord. Python imports your own file first, so the real library is hidden. Rename it.
'pip' is not recognized, or 'python' opens the Microsoft Store
On Windows this means the command is not on your PATH. Use the py launcher shown above, which the official page recommends for Windows. It does not depend on PATH settings.
Python version too old
The library requires Python 3.8 or higher. Check yours with python3 --version. If it is older, install a current Python and create a new virtual environment with it. Do not try to force the install on 3.7 or earlier.
PrivilegedIntentsRequired
The library raises discord.PrivilegedIntentsRequired when your code requests a privileged intent that is not switched on in the developer portal. Per the source code, the message starts: Shard ID %s is requesting privileged intents that have not been explicitly enabled in the developer portal. (the shard ID in the message depends on your setup). The docstring names three intents that need the tick box: members, presences and message_content.
The fix is in the Developer Portal. Open the application page at https://discord.com/developers/applications, pick your bot, open the Bot tab, scroll to "Privileged Gateway Intents" and enable the intents your code uses. The documentation adds that bots in more than 100 guilds must go through bot verification before they can enable privileged intents.
The bot is online but ignores commands
If your code does not set intents.message_content = True, the bot cannot read what people type. The intents guide is explicit: "Even if you enable intents through the developer portal, you still have to enable the intents through code as well." Both halves are required.
LoginFailure
discord.LoginFailure is documented as raised when the wrong credentials are passed. In practice, check that the token was copied completely, that it has no extra spaces or quotes, and that your environment variable is actually set in the terminal you are running from. If a token was ever pasted into a public place, generate a new one in the portal.
Keep the token out of your code
The example above reads os.environ["DISCORD_TOKEN"]. Set it for the current terminal session in PowerShell with $env:DISCORD_TOKEN = "your-token-here", or on macOS and Linux with export DISCORD_TOKEN="your-token-here". The variable lasts only for that terminal window. If the variable is missing, the script stops with a KeyError, which is better than silently running with an empty token.
Frequently asked questions
- Is the package called discord or discord.py?
- Install it as discord.py (pip install discord.py). You then import it in code as discord, with import discord. The two names differ, which is a common source of confusion.
- Which Python version does discord.py need?
- The official installation page says Python 3.8 or higher, and the PyPI page lists the same requirement as of version 2.7.1. Python 3.7 and earlier are not supported.
- Do I need the voice extra?
- Only if your bot joins voice channels. Install it with pip install "discord.py[voice]", which adds PyNaCl. A bot that only reads and sends text messages does not need it.
- Why does my bot connect but never reply to messages?
- Most often the Message Content intent is off. It must be enabled in the Discord Developer Portal and also turned on in code with intents.message_content = True. The documentation states that enabling it in the portal alone is not enough.
- Where should I keep my bot token?
- Outside your source code, for example in an environment variable that your script reads at start-up. Anyone who has the token can control your bot, so never paste it into a file you commit or share.