A modern, easy-to-use, feature-rich async-ready API wrapper for Discord written in Python
npx @tessl/cli install tessl/pypi-disnake@2.10.0A modern, easy-to-use, feature-rich, and async-ready API wrapper for Discord written in Python. Disnake enables developers to create Discord bots and applications with proper rate limit handling, type-safety measures, and FastAPI-like slash command syntax while preserving the syntax and structure of discord.py 2.0.
pip install disnakepip install disnake[voice]import disnakeCommon imports for bot development:
from disnake.ext import commands
import disnakeimport disnake
from disnake.ext import commands
# Create a bot with message commands
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
print(f'Bot is ready! Logged in as {bot.user}')
@bot.slash_command(description="Say hello")
async def hello(inter: disnake.ApplicationCommandInteraction):
await inter.response.send_message("Hello!")
@bot.command()
async def ping(ctx):
await ctx.send('Pong!')
# Run the bot
bot.run('YOUR_BOT_TOKEN')Disnake follows a hierarchical event-driven architecture:
This design provides both backward compatibility with discord.py and modern Discord API features including interactions, UI components, and comprehensive bot development tools.
Core client and bot classes for establishing Discord connections and managing bot functionality. Includes both basic clients and specialized bot classes for different use cases.
class Client:
def __init__(self, **options): ...
async def login(self, token: str): ...
async def connect(self, *, reconnect: bool = True): ...
def run(self, token: str, **kwargs): ...
async def close(): ...
class Bot(commands.BotBase, Client):
def __init__(self, command_prefix, **options): ...Comprehensive channel types and messaging functionality supporting text channels, voice channels, threads, forums, and direct messages. Includes message creation, editing, deletion, and rich content support.
class TextChannel:
async def send(self, content=None, **kwargs) -> Message: ...
async def fetch_message(self, id: int) -> Message: ...
class Message:
content: str
author: Union[User, Member]
channel: Messageable
async def edit(self, **kwargs): ...
async def delete(): ...Modern Discord application commands including slash commands, user context menu commands, and message context menu commands with parameter validation and autocomplete support.
def slash_command(name=None, description=None, **kwargs):
"""Decorator for slash commands"""
def user_command(name=None, **kwargs):
"""Decorator for user context menu commands"""
def message_command(name=None, **kwargs):
"""Decorator for message context menu commands"""Interactive Discord UI elements including buttons, select menus, modals, and views for creating rich user interfaces with persistent component handling.
class View:
def __init__(self, **kwargs): ...
async def interaction_check(self, interaction: Interaction) -> bool: ...
class Button(Item):
def __init__(self, style=ButtonStyle.secondary, label=None, **kwargs): ...
async def callback(self, interaction: Interaction): ...
class Modal:
def __init__(self, title: str, **kwargs): ...
async def on_submit(self, interaction: ModalInteraction): ...Interactions and UI Components
Comprehensive guild (server) management including member management, role management, channel organization, permissions, and guild-specific features like scheduled events and moderation.
class Guild:
name: str
members: List[Member]
channels: List[GuildChannel]
roles: List[Role]
async def create_text_channel(self, name: str, **kwargs) -> TextChannel: ...
async def ban(self, user, **kwargs): ...User and member objects representing Discord users and guild members with profile information, permissions, voice states, and user-specific operations.
class User:
id: int
name: str
discriminator: str
avatar: Optional[Asset]
class Member(User):
guild: Guild
roles: List[Role]
joined_at: Optional[datetime]
async def add_roles(*roles): ...Discord gateway events and event handling system for real-time bot functionality including message events, member events, guild events, and custom event dispatching.
@bot.event
async def on_ready(): ...
@bot.event
async def on_message(message: Message): ...
@bot.event
async def on_member_join(member: Member): ...Traditional message-based command framework with command groups, argument parsing, permission checks, cooldowns, and error handling for text-based bot commands.
@commands.command()
async def my_command(ctx: commands.Context): ...
@commands.group()
async def my_group(ctx: commands.Context): ...
@commands.check(lambda ctx: ctx.author.id == 123456789)
async def owner_only(ctx): ...Discord permissions system, role management, and security features including permission overrides, role hierarchy, and access control for commands and features.
class Permissions:
def __init__(self, **kwargs): ...
@classmethod
def all(cls): ...
@classmethod
def none(cls): ...
class PermissionOverwrite:
def __init__(self, **kwargs): ...Comprehensive error handling system covering Discord API errors, command framework errors, interaction errors, and custom exception types with proper error recovery patterns.
class DiscordException(Exception): ...
class HTTPException(DiscordException): ...
class CommandError(DiscordException): ...
class InteractionException(DiscordException): ...
@bot.event
async def on_command_error(ctx, error): ...Voice channel connection, audio streaming, and voice-related functionality for music bots and voice applications with proper audio handling and connection management.
class VoiceChannel:
async def connect(self, **kwargs) -> VoiceClient: ...
class VoiceClient:
async def disconnect(): ...
def play(self, source, **kwargs): ...Comprehensive i18n system for application commands with support for Discord's native localization features, file-based translation stores, and custom localization providers.
class Localized:
def __init__(self, string, *, key=None, **localizations): ...
def set(self, locale, value): ...
class LocalizationStore(LocalizationProtocol):
def __init__(self, files, *, strict=False, fallback=None): ...
async def get(self, key, locale, **kwargs): ...Localization and Internationalization
Discord's automated content moderation system with configurable rules, triggers, and actions for filtering messages, managing spam, and enforcing community guidelines.
class AutoModRule:
@property
def name(self) -> str: ...
@property
def trigger_type(self) -> AutoModTriggerType: ...
async def edit(self, **kwargs) -> AutoModRule: ...
async def delete(self) -> None: ...
class AutoModAction:
@property
def type(self) -> AutoModActionType: ...Discord's native poll system with multi-choice answers, emoji support, vote tracking, and automatic result counting for interactive community engagement.
class Poll:
@property
def question(self) -> PollMedia: ...
@property
def answers(self) -> List[PollAnswer]: ...
async def end(self) -> Message: ...
@classmethod
def create(cls, question, *answers, duration=None, allow_multiselect=False): ...
class PollAnswer:
@property
def vote_count(self) -> int: ...
def get_voters(self) -> PollAnswerIterator: ...