A Python wrapper for the Discord API forked from discord.py
npx @tessl/cli install tessl/pypi-nextcord@2.6.0A modern, comprehensive Python library that provides an async-ready API wrapper for Discord's bot API, forked from discord.py. It offers a feature-rich, Pythonic interface for building Discord bots with support for slash commands, message components, auto-moderation, voice capabilities, and proper rate limiting.
pip install nextcordpip install nextcord[voice]pip install nextcord[speed]import nextcordCommon imports for bot development:
from nextcord import Client, Intents, Activity, ActivityType, Status
from nextcord.ext import commandsFor UI components:
from nextcord.ui import View, Button, Select, Modal, TextInputFor background tasks:
from nextcord.ext import tasksimport nextcord
from nextcord.ext import commands
# Create bot with command prefix
bot = commands.Bot(command_prefix='!', intents=nextcord.Intents.default())
@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')
@bot.command(name='hello')
async def hello(ctx):
await ctx.send(f'Hello {ctx.author.mention}!')
# Run the bot
bot.run('YOUR_BOT_TOKEN')@bot.slash_command(description="Say hello to someone")
async def hello(interaction: nextcord.Interaction, user: nextcord.Member):
await interaction.response.send_message(f'Hello {user.mention}!')from nextcord.ui import View, Button
class MyView(View):
@nextcord.ui.button(label='Click me!', style=nextcord.ButtonStyle.primary)
async def button_callback(self, button, interaction):
await interaction.response.send_message('Button clicked!', ephemeral=True)
@bot.slash_command()
async def ui_demo(interaction: nextcord.Interaction):
view = MyView()
await interaction.response.send_message('Here is a button:', view=view)Nextcord follows a hierarchical architecture centered around the Discord API structure:
The async/await pattern provides efficient concurrent handling of Discord events and API calls, while the cog system enables organized, modular bot architecture.
Core client classes for connecting to Discord, managing bot lifecycle, handling events, and maintaining connections with proper sharding support for large bots.
class Client:
def __init__(self, *, intents: Intents, **options): ...
async def start(self, token: str): ...
async def close(): ...
def run(self, token: str): ...
class AutoShardedClient(Client):
def __init__(self, *, shard_count: int = None, **options): ...Comprehensive server management including member operations, role management, channel organization, moderation tools, and server configuration.
class Guild:
async def create_text_channel(self, name: str, **options) -> TextChannel: ...
async def create_voice_channel(self, name: str, **options) -> VoiceChannel: ...
async def ban(self, user: nextcord.abc.Snowflake, **options): ...
async def kick(self, user: Member, reason: str = None): ...Complete channel management for all Discord channel types including text channels, voice channels, stage channels, threads, and forum channels with their specific capabilities.
class TextChannel(nextcord.abc.Messageable):
async def send(self, content: str = None, **kwargs) -> Message: ...
async def create_thread(self, **kwargs) -> Thread: ...
class VoiceChannel(nextcord.abc.GuildChannel):
async def connect(**kwargs) -> VoiceClient: ...Message handling, content creation, embed formatting, file attachments, and reaction management for rich Discord communication.
class Message:
async def reply(self, content: str = None, **kwargs) -> Message: ...
async def add_reaction(self, emoji): ...
async def edit(self, **kwargs) -> Message: ...
class Embed:
def __init__(self, **kwargs): ...
def add_field(self, *, name: str, value: str, inline: bool = True): ...Modern Discord application commands including slash commands, user commands, message commands, and their interaction handling.
def slash_command(*, name: str = None, description: str = None, **kwargs): ...
def user_command(*, name: str = None, **kwargs): ...
def message_command(*, name: str = None, **kwargs): ...
class Interaction:
response: InteractionResponse
followup: Followup
class InteractionResponse:
async def send_message(self, content: str = None, **kwargs): ...
class Followup:
async def send(self, content: str = None, **kwargs): ...Interactive Discord UI components including views, buttons, select menus, modals, and text inputs for rich user interactions.
class View:
def __init__(self, *, timeout: float = 180.0): ...
async def interaction_check(self, interaction: Interaction) -> bool: ...
class Button(nextcord.ui.Item):
def __init__(self, *, style: ButtonStyle = ButtonStyle.secondary, **kwargs): ...
class Modal:
def __init__(self, **kwargs): ...
async def on_submit(self, interaction: Interaction): ...User representation, member management, permission handling, and voice state tracking for comprehensive user operations.
class User:
async def send(self, content: str = None, **kwargs) -> Message: ...
class Member(User):
async def add_roles(*roles, reason: str = None): ...
async def remove_roles(*roles, reason: str = None): ...
async def timeout(self, until: datetime.datetime, reason: str = None): ...Comprehensive permission management, role operations, and access control for Discord servers.
class Role:
async def edit(self, **kwargs): ...
async def delete(reason: str = None): ...
class Permissions:
def __init__(self, permissions: int = 0): ...
def update(self, **kwargs): ...Traditional text-based command system with the commands extension, providing prefix commands, command groups, converters, and checks.
class Bot(commands.Bot):
def __init__(self, command_prefix, **options): ...
def command(name: str = None, **kwargs): ...
def group(name: str = None, **kwargs): ...
class Context:
async def send(self, content: str = None, **kwargs) -> Message: ...Task scheduling and background operations with the tasks extension for periodic and scheduled operations.
def loop(*, seconds: float = None, minutes: float = None, hours: float = None): ...
class Loop:
def start(self, *args, **kwargs): ...
def stop(self): ...
def restart(self, *args, **kwargs): ...Webhook creation and management for external integrations and message delivery outside of bot connections.
class Webhook:
async def send(self, content: str = None, **kwargs) -> WebhookMessage: ...
async def edit_message(self, message_id: int, **kwargs) -> WebhookMessage: ...
class SyncWebhook:
def send(self, content: str = None, **kwargs) -> WebhookMessage: ...Voice connection management, audio playback, and voice state handling for Discord voice features.
class VoiceClient:
def play(self, source: AudioSource, *, after=None): ...
def stop(self): ...
async def disconnect(self, *, force: bool = False): ...
class AudioSource:
def read(self) -> bytes: ...Event handling system for Discord gateway events and raw event data for advanced use cases.
@bot.event
async def on_message(message: Message): ...
@bot.event
async def on_raw_message_delete(payload: RawMessageDeleteEvent): ...Utility functions, helper classes, and convenience methods for common Discord bot operations.
def find(predicate, iterable): ...
def get(iterable, **attrs): ...
def oauth_url(client_id: int, *, permissions: Permissions = None, **kwargs) -> str: ...Exception hierarchy and error handling patterns for robust Discord bot development.
class DiscordException(Exception): ...
class HTTPException(DiscordException): ...
class Forbidden(HTTPException): ...
class NotFound(HTTPException): ...