#
API Reference
Complete API documentation for Sonora.
#
SonoraClient
The main client class for interacting with Lavalink nodes.
#
Constructor
SonoraClient(
lavalink_nodes: list[dict],
node_pooling: bool = True,
reconnect_policy: dict | None = None,
user_id: int | None = None
)
Parameters:
lavalink_nodes: List of node configurationsnode_pooling: Enable load balancing across nodesreconnect_policy: Reconnection settingsuser_id: Discord user ID for the bot
#
Methods
#
async start()
Initialize the client and connect to nodes.
#
async close()
Shutdown the client and disconnect from all nodes.
#
async get_player(guild_id: int) -> Player
Get or create a player for a Discord guild.
#
Player
Represents a music player for a Discord guild.
#
Methods
#
async play(query: str) -> Track
Search and play a track.
#
async skip() -> Track | None
Skip to the next track.
#
async stop()
Stop playback and clear the queue.
#
async pause()
Pause playback.
#
async resume()
Resume playback.
#
async seek(position: int)
Seek to a position in the current track.
#
async set_volume(volume: int)
Set playback volume (0-1000).
#
async destroy()
Destroy the player and clean up resources.
#
Properties
current: Track | None- Currently playing trackqueue: SmartQueue- The player's queuepaused: bool- Whether playback is pausedvolume: int- Current volume levelposition: int- Current playback position
#
SmartQueue
Intelligent queue with advanced features.
#
Methods
#
async add(track: Track, position: int | None = None)
Add a track to the queue.
#
async add_multiple(tracks: list[Track], position: int | None = None)
Add multiple tracks to the queue.
#
async pop(position: int = 0) -> Track
Remove and return a track from the queue.
#
async clear()
Clear all tracks from the queue.
#
async smart_shuffle()
Shuffle the queue while preserving recently played tracks.
#
async perform_adaptive_reorder()
Reorder queue based on popularity metrics.
#
Properties
current: Track | None- Currently playing trackupcoming: list[Track]- Tracks waiting to be playedhistory: list[Track]- Recently played trackslength: int- Number of upcoming tracksis_empty: bool- Whether the queue is empty
#
Track
Represents an audio track.
#
Properties
title: str- Track titleauthor: str- Track author/artisturi: str- Track URLidentifier: str- Lavalink track identifierlength: int- Track duration in millisecondsis_stream: bool- Whether the track is a live streamis_seekable: bool- Whether the track supports seeking
#
AutoplayEngine
Handles automatic track recommendations.
#
Methods
#
async fetch_next_track(context: dict) -> Track | None
Get the next recommended track based on context.
#
async start()
Start the autoplay engine.
#
async stop()
Stop the autoplay engine.
#
Configuration
enabled: bool- Whether autoplay is enabledstrategy: str- Recommendation strategy ('similar_artist', 'similar_genre', etc.)max_history: int- Maximum history tracks to considersmart_shuffle: bool- Enable smart shuffling
#
Filters
Audio filter management.
#
Available Filters
BassBoost- Enhance low frequenciesNightcore- Increase speed and pitchReverb- Add echo effectsEqualizer- Frequency-specific adjustments
#
Methods
#
async set_filter(filter_name: str, **kwargs)
Apply an audio filter.
#
async clear_filters()
Remove all active filters.
#
async reset_filters()
Reset filters to default state.
#
Node
Represents a Lavalink node connection.
#
Methods
#
async connect()
Connect to the Lavalink node.
#
async disconnect()
Disconnect from the node.
#
async send(op: str, **data)
Send a payload to the node.
#
async receive() -> dict
Receive a payload from the node.
#
Properties
connected: bool- Connection statusstats: dict- Node statistics
#
Events
Event system for handling Lavalink events.
#
Event Types
TRACK_START- Track started playingTRACK_END- Track finished playingTRACK_EXCEPTION- Track encountered an errorQUEUE_EMPTY- Queue became emptyPLAYER_UPDATE- Player state changed
#
Usage
from sonora import event_manager, EventType
@event_manager.on(EventType.TRACK_START)
async def on_track_start(event):
print(f"Started playing: {event.data['track'].title}")
#
Exceptions
#
SonoraError
Base exception for Sonora-related errors.
#
NodeException
Raised when node operations fail.
#
TrackLoadError
Raised when track loading fails.
#
Security
Security-related classes and functions.
#
CredentialManager
Manages encrypted credentials.
#
PluginFirewall
Sandboxes plugin execution.
#
SecureDeserializationLayer
Safe JSON deserialization with validation.