Client interface is the core component of DisGoLink, managing Lavalink nodes, players, and event listeners.
Creating a Client
Create a new client withdisgolink.New():
The Discord bot’s user ID
Configuration Options
Customize the client withConfigOpt functions:
Available Options
Inject a custom structured logger
Provide a custom HTTP client for REST requests (default timeout: 10s)
Register event listeners at initialization
Register a typed event listener function
Add plugins to extend functionality
Node Management
Adding Nodes
Connect to a Lavalink server:Adds and connects to a new Lavalink node. Returns immediately after establishing connection.
Retrieving Nodes
Get a specific node by name
Automatically select the node with the best performance based on CPU, memory, and system load statistics
Iterate over all registered nodes
Disconnect and remove a node by name
Player Management
Creating Players
Get or create a player for a guild using the best available node
Get or create a player on a specific node
Get an existing player without creating a new one (returns nil if not found)
Managing Players
Iterate over all active players
Remove a player from the client’s cache (does not destroy the player on the node)
Event System
Adding Listeners
Register one or more event listeners
Unregister event listeners
Manually emit an event to all registered listeners (typically used internally)
Voice State Updates
Forward Discord voice events to the client:Handle Discord VOICE_SERVER_UPDATE eventsParameters:
ctx: ContextguildID: Guild snowflake IDtoken: Voice connection tokenendpoint: Voice server endpoint
Handle Discord VOICE_STATE_UPDATE eventsParameters:
ctx: ContextguildID: Guild snowflake IDchannelID: Voice channel ID (nil if disconnected)sessionID: Voice session ID
Additional Methods
Get the bot’s user ID
Close all node connections and shut down the client
Plugin System
Extend client functionality with plugins:Register plugins
Iterate over registered plugins
Unregister plugins
Plugins can implement various interfaces like
PluginEventHandler, EventPlugin, and OpPlugin to hook into different lifecycle events.