{"id":7529,"library":"py-cord","title":"Pycord","description":"Pycord is a modern, easy-to-use, and feature-rich Python wrapper for the Discord API. It enables developers to build Discord bots with support for slash commands, UI components, voice functionality, and more. The library is actively maintained with frequent minor updates and occasional major version releases to align with Discord API changes and introduce new features.","status":"active","version":"2.7.2","language":"en","source_language":"en","source_url":"https://github.com/Pycord-Development/pycord","tags":["discord","bot","async","api-wrapper","slash-commands","ui-components"],"install":[{"cmd":"pip install -U py-cord","lang":"bash","label":"Basic installation"},{"cmd":"pip install -U \"py-cord[voice]\"","lang":"bash","label":"With voice support"}],"dependencies":[{"reason":"Required for voice support.","package":"PyNaCl","optional":true},{"reason":"Optional speedups for aiohttp.","package":"aiodns, brotlipy, cchardet","optional":true},{"reason":"Optional speedup for JSON processing.","package":"msgspec","optional":true}],"imports":[{"note":"The primary class for creating a Discord bot with command handling capabilities.","symbol":"Bot","correct":"from discord import Bot"},{"note":"A lower-level alternative to Bot, often used for simple event-driven bots without command framework needs.","symbol":"Client","correct":"from discord import Client"},{"note":"Required for specifying which events your bot will receive from Discord.","symbol":"Intents","correct":"from discord import Intents"},{"note":"The context object passed to application commands (e.g., slash commands).","symbol":"ApplicationContext","correct":"from discord import ApplicationContext"}],"quickstart":{"code":"import discord\nimport os\n\n# Enable necessary intents. message_content is privileged for text commands.\nintents = discord.Intents.default()\nintents.message_content = True # Required for reading message content in commands or on_message events\n\nbot = discord.Bot(intents=intents)\n\n@bot.event\nasync def on_ready():\n    print(f\"{bot.user} is ready and online!\")\n\n@bot.slash_command(name=\"hello\", description=\"Say hello to the bot\")\nasync def hello(ctx: discord.ApplicationContext, name: str = None):\n    \"\"\"Says hello to the user or a specified name.\"\"\"\n    name = name or ctx.author.name\n    await ctx.respond(f\"Hello {name}!\")\n\n# Run the bot with the token from environment variables\n# Make sure to set a 'TOKEN' environment variable with your bot's token\nbot.run(os.environ.get('TOKEN'))\n","lang":"python","description":"This quickstart demonstrates a basic Pycord bot that comes online and responds to a slash command '/hello'. It highlights the use of `discord.Bot`, `Intents`, and retrieving the bot token from an environment variable for security. Remember to enable the 'Message Content' privileged intent in your bot's Discord Developer Portal settings for `intents.message_content = True` to function correctly."},"warnings":[{"fix":"Upgrade your Python environment to version 3.10 or higher (up to 3.13) to ensure compatibility.","message":"Pycord v2.7.0 dropped support for Python 3.8 and 3.9. Python 3.7 and below were dropped in v2.0. The library currently requires Python >=3.10 and <3.14.","severity":"breaking","affected_versions":">=2.7.0 (for 3.8/3.9), >=2.0 (for 3.7 and below)"},{"fix":"Initialize your bot with `intents = discord.Intents.default()` (or specific intents) and pass them to the bot constructor (`bot = discord.Bot(intents=intents)`). For privileged intents, also enable them in the Discord Developer Portal under your bot's settings.","message":"Gateway Intents are now explicitly required when initializing `discord.Client` or `discord.Bot`. Additionally, `Intents.message_content`, `Intents.members`, and `Intents.presences` are 'privileged intents' and must be manually enabled in your bot's Discord Developer Portal settings.","severity":"breaking","affected_versions":">=2.0"},{"fix":"Refer to the official 'Migrating to v2.0' guide in the Pycord documentation for a comprehensive list of changes and migration steps.","message":"Migrating from py-cord v1.x to v2.x involves significant breaking changes, including a new `discord.Bot` class for application commands, redesigned UI components, removal of user account support, and changes to webhook handling. Old `discord.py` code may require substantial updates.","severity":"breaking","affected_versions":">=2.0"},{"fix":"Upgrade Pycord to version 2.7.2 or later to include the fix.","message":"A `KeyError` could occur when fetching application information or checking ownership (`is_owner`) due to `read_only` team members not being considered owners. This was a recent fix.","severity":"gotcha","affected_versions":"<2.7.2, <2.8.0rc2"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Go to the Discord Developer Portal, select your application, navigate to the 'Bot' tab, and enable the necessary privileged intents under 'Privileged Gateway Intents'. Also, ensure these intents are passed to your `discord.Bot` or `discord.Client` instance (e.g., `intents.message_content = True`).","cause":"Your bot is attempting to use a privileged intent (e.g., Message Content, Members, or Presences) that has not been enabled in your Discord Developer Portal settings or not specified in your bot's code.","error":"discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal."},{"fix":"Check your bot's role permissions in the Discord server and ensure its highest role is above the roles it's trying to manage. Also, verify that the bot has the required permissions enabled in the Discord Developer Portal and during its invite process (OAuth2 URL Generator). If MFA is required for the server, ensure your developer account has it enabled.","cause":"Your bot lacks the necessary permissions to perform an action (e.g., sending messages in a channel, assigning roles, kicking members) in the Discord server. This can be due to bot role hierarchy or missing permissions in the developer portal/server.","error":"discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access"},{"fix":"Enable the 'Message Content Intent' in your bot's settings on the Discord Developer Portal, and ensure `intents.message_content = True` is set when initializing your `discord.Bot` or `discord.Client` instance.","cause":"The `message_content` privileged intent is not enabled, preventing your bot from accessing the content of messages sent by other users.","error":"message.content is empty / Bot not reading message content"},{"fix":"For slash commands, ensure all required options are placed before any optional options. For messages, verify the content is not empty, does not exceed 2000 characters, and any embeds or components are correctly structured and populated.","cause":"This error often occurs with slash commands when required options are defined after optional ones, or when the message content (e.g., in an embed) is malformed or empty, or exceeds Discord's character limits (2000 characters for a message).","error":"discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body"}]}