Discord API (discord.py)

2.7.1 · active · verified Tue Mar 17

Community-maintained Python wrapper for the Discord API. Current version is 2.7.1 (Mar 2026). PyPI package is 'discord.py' (with dot), imports as 'discord'. Note: 'pip install discord' installs a mirror stub that redirects to discord.py — always install discord.py directly. The library was abandoned in 2021 and resumed in 2022 with a full v2 rewrite; vast amounts of pre-v2 tutorial code is broken.

Warnings

Install

Imports

Quickstart

Minimal prefix command bot with required intents declaration (v2.x).

import discord
from discord.ext import commands

# Intents are REQUIRED in v2 — no defaults silently work
intents = discord.Intents.default()
intents.message_content = True  # privileged intent — must enable in Dev Portal too

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.command()
async def ping(ctx):
    await ctx.send('pong')

bot.run('YOUR_BOT_TOKEN')

view raw JSON →