Registry / communication / discord-py

discord-py

JSON →
library2.7.1pypypiunverified

Discord.py is a modern, easy to use, feature-rich, and async ready API wrapper for Discord, written in Python. The current version is 2.7.1, and it is actively maintained with regular updates to support Discord API changes and new features.

communication
pip install -U discord.py
Install & Compatibility
Where this runs
tested against v2.7.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.950 runs
installs and imports cleanly · install 0.0s · import 0.861s · 42.9MB
glibc
py 3.103.950 runs
installs and imports cleanly · install 4.7s · import 0.791s · 44MB
42MB installed
● package 42MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
import discord client = discord.Client(intents=...)
client = discord.Client()
As of v2.0, `intents` are a required keyword argument for `discord.Client` and its subclasses.
Bot
from discord.ext import commands bot = commands.Bot(command_prefix='!', intents=...)
bot = commands.Bot(command_prefix='!')
As of v2.0, `intents` are a required keyword argument for `commands.Bot`.
Intents
intents = discord.Intents.default() intents.message_content = True
intents = discord.Intents.all() # Or not enabling specific privileged intents
`message_content` is a privileged intent and must be explicitly enabled in both code and the Discord Developer Portal if your bot processes message content.

This quickstart demonstrates a minimal Discord bot that responds to a '$hello' message. It highlights the explicit requirement for `discord.Intents` and enabling the `message_content` privileged intent, which is crucial for bots interacting with message content in v2.0 and newer.

import os import discord intents = discord.Intents.default() intents.message_content = True # Required for on_message to access message.content client = discord.Client(intents=intents) @client.event async def on_ready(): print(f'We have 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!') # Replace 'YOUR_BOT_TOKEN' with your actual bot token, ideally from environment variables. # Ensure DISCORD_TOKEN is set in your environment for production. client.run(os.environ.get('DISCORD_TOKEN', 'YOUR_BOT_TOKEN'))
Debug
Known issues
breakingDiscord.py v2.0 and later require Python 3.8 or higher. Projects on older Python versions must upgrade to use the latest library features.
fix
Upgrade your Python installation to version 3.8 or newer.
affects: 2.0.0+
breakingGateway Intents are now a mandatory keyword argument for `discord.Client` and `discord.ext.commands.Bot` instances. Failing to provide them will raise an error.
fix
Pass an `intents` object (e.g., `discord.Intents.default()`) to the client/bot constructor.
affects: 2.0.0+
breakingThe `message_content` intent is now a privileged intent. To access `message.content`, `message.embeds`, or `message.attachments`, this intent must be enabled both in your bot's code (`intents.message_content = True`) and on the Discord Developer Portal.
fix
Enable `message_content` intent in your code and on the Discord Developer Portal under your bot's 'Privileged Gateway Intents' settings.
affects: 2.0.0+
breakingUser account (self-bot) support has been completely removed in v2.0 due to violations of Discord's Terms of Service.
fix
Migrate any self-bot functionality to official bot accounts using the standard API.
affects: 2.0.0+
breakingThe `Client.logout()` method has been removed. Use `Client.close()` instead to properly close the connection to Discord.
fix
Replace `await client.logout()` with `await client.close()`.
affects: 2.0.0+
gotchaDo not name your bot's Python file `discord.py` as this will cause import conflicts with the library itself.
fix
Rename your bot's file to something like `my_bot.py` or `main.py`.
affects: All
gotchaYour bot token is a sensitive secret. Never hardcode it directly in your code or share it publicly. Use environment variables (e.g., `os.environ.get('DISCORD_TOKEN')`) to store and retrieve it securely.
fix
Store your bot token in an environment variable or a secure configuration file, and access it programmatically.
affects: All
Upgrade
Version history
2.7.1latest on PyPI
Audit
Dependencies
PythonrequiredRequires Python 3.8 or higher.
libffi-devoptionalRequired for voice support on Linux/macOS.
python-devoptionalRequired for voice support on Linux/macOS (e.g., python3.8-dev).
Agent activity
57 hits · last 30 days
node
12
claudebot
4
seranking-bot
4
ahrefsbot
3
bytedance
2
amazonbot
1
Resources