or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

application-commands.mdchannels.mdclient.mdcommands.mderrors.mdevents.mdguild.mdindex.mdmessages.mdpermissions.mdtasks.mdui.mdusers.mdutilities.mdvoice.mdwebhooks.md
tile.json

tessl/pypi-nextcord

A Python wrapper for the Discord API forked from discord.py

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/nextcord@2.6.x

To install, run

npx @tessl/cli install tessl/pypi-nextcord@2.6.0

index.mddocs/

Nextcord

A 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.

Package Information

  • Package Name: nextcord
  • Language: Python
  • Installation: pip install nextcord
  • Voice Support: pip install nextcord[voice]
  • Speed Optimization: pip install nextcord[speed]

Core Imports

import nextcord

Common imports for bot development:

from nextcord import Client, Intents, Activity, ActivityType, Status
from nextcord.ext import commands

For UI components:

from nextcord.ui import View, Button, Select, Modal, TextInput

For background tasks:

from nextcord.ext import tasks

Basic Usage

Simple Bot with Client

import 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')

Slash Commands

@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}!')

UI Components

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)

Architecture

Nextcord follows a hierarchical architecture centered around the Discord API structure:

  • Client/Bot: Central connection and event management
  • Guilds (Servers): Server containers with members, channels, and roles
  • Channels: Communication endpoints (text, voice, stage, threads)
  • Users/Members: User representations with guild-specific attributes
  • Messages: Content delivery with embeds, attachments, and components
  • Interactions: Modern Discord features (slash commands, buttons, modals)
  • Extensions: Modular functionality (commands framework, tasks, checks)

The async/await pattern provides efficient concurrent handling of Discord events and API calls, while the cog system enables organized, modular bot architecture.

Capabilities

Client and Connection Management

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): ...

Client and Connection

Guild and Server Management

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): ...

Guild Management

Channel System

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: ...

Channel System

Message and Communication

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): ...

Messages and Content

Application Commands (Slash Commands)

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): ...

Application Commands

UI Framework

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): ...

UI Framework

User and Member Management

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): ...

Users and Members

Permission and Role System

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): ...

Permissions and Roles

Command Framework

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: ...

Command Framework

Background Tasks

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): ...

Tasks and Scheduling

Webhook System

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: ...

Webhooks

Voice and Audio

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: ...

Voice and Audio

Events and Raw Events

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): ...

Events

Utilities and Helpers

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: ...

Utilities

Error Handling

Exception hierarchy and error handling patterns for robust Discord bot development.

class DiscordException(Exception): ...
class HTTPException(DiscordException): ...
class Forbidden(HTTPException): ...
class NotFound(HTTPException): ...

Error Handling