{"id":1993,"library":"discord-py","title":"Discord.py","description":"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.","status":"active","version":"2.7.1","language":"en","source_language":"en","source_url":"https://github.com/Rapptz/discord.py","tags":["discord","bot","async","api-wrapper","chat"],"install":[{"cmd":"pip install -U discord.py","lang":"bash","label":"Stable Release"},{"cmd":"pip install -U \"discord.py[voice]\"","lang":"bash","label":"With Voice Support"}],"dependencies":[{"reason":"Requires Python 3.8 or higher.","package":"Python","optional":false},{"reason":"Required for voice support on Linux/macOS.","package":"libffi-dev","optional":true},{"reason":"Required for voice support on Linux/macOS (e.g., python3.8-dev).","package":"python-dev","optional":true}],"imports":[{"note":"As of v2.0, `intents` are a required keyword argument for `discord.Client` and its subclasses.","wrong":"client = discord.Client()","symbol":"Client","correct":"import discord\nclient = discord.Client(intents=...)"},{"note":"As of v2.0, `intents` are a required keyword argument for `commands.Bot`.","wrong":"bot = commands.Bot(command_prefix='!')","symbol":"Bot","correct":"from discord.ext import commands\nbot = commands.Bot(command_prefix='!', intents=...)"},{"note":"`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.","wrong":"intents = discord.Intents.all() # Or not enabling specific privileged intents","symbol":"Intents","correct":"intents = discord.Intents.default()\nintents.message_content = True"}],"quickstart":{"code":"import os\nimport discord\n\nintents = discord.Intents.default()\nintents.message_content = True # Required for on_message to access message.content\n\nclient = discord.Client(intents=intents)\n\n@client.event\nasync def on_ready():\n    print(f'We have logged in as {client.user}')\n\n@client.event\nasync def on_message(message):\n    if message.author == client.user:\n        return\n\n    if message.content.startswith('$hello'):\n        await message.channel.send('Hello!')\n\n# Replace 'YOUR_BOT_TOKEN' with your actual bot token, ideally from environment variables.\n# Ensure DISCORD_TOKEN is set in your environment for production.\nclient.run(os.environ.get('DISCORD_TOKEN', 'YOUR_BOT_TOKEN'))","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python installation to version 3.8 or newer.","message":"Discord.py v2.0 and later require Python 3.8 or higher. Projects on older Python versions must upgrade to use the latest library features.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Pass an `intents` object (e.g., `discord.Intents.default()`) to the client/bot constructor.","message":"Gateway Intents are now a mandatory keyword argument for `discord.Client` and `discord.ext.commands.Bot` instances. Failing to provide them will raise an error.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Enable `message_content` intent in your code and on the Discord Developer Portal under your bot's 'Privileged Gateway Intents' settings.","message":"The `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.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Migrate any self-bot functionality to official bot accounts using the standard API.","message":"User account (self-bot) support has been completely removed in v2.0 due to violations of Discord's Terms of Service.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Replace `await client.logout()` with `await client.close()`.","message":"The `Client.logout()` method has been removed. Use `Client.close()` instead to properly close the connection to Discord.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Rename your bot's file to something like `my_bot.py` or `main.py`.","message":"Do not name your bot's Python file `discord.py` as this will cause import conflicts with the library itself.","severity":"gotcha","affected_versions":"All"},{"fix":"Store your bot token in an environment variable or a secure configuration file, and access it programmatically.","message":"Your 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}