Lavalink4NET is a Lavalink wrapper with node clustering, caching and custom players for .NET with support for Discord.Net and DSharpPlus.
- 🔌 Asynchronous Interface
- ⚖️ Node Clustering / Load Balancing
- ✳️ Extensible
- 🎤 Lyrics
- 🗳️ Queueing / Voting-System
- 🎵 Track Decoding
- 🔄 Auto-Reconnect and Resuming
- 📝 Logging (optional)
- ⚡ Request Caching (optional)
- ⏱️ Inactivity Tracking (optional)
- ➕ Compatible with DSharpPlus and Discord.Net.
and a lot more...
- Download Lavalink4NET Core
- Download Lavalink4NET for Discord.Net
- Download Lavalink4NET for DSharpPlus
- Download Lavalink4NET MemoryCache
- One or more Lavalink Nodes
- .NET Core >= 2.0
You can use Lavalink4NET in 3 different modes: Cluster, Node and Rest.
- Cluster is useful for combining a bunch of nodes to one to load balance.
- Node is useful when you have a small discord bot with one Lavalink Node.
- Rest is useful when you only want to resolve tracks.
Here is an example, how you can create the AudioService for a single node:
var audioService = new LavalinkNode(new LavalinkNodeOptions
{
RestUri = "http://localhost:8080/",
WebSocketUri = "ws://localhost:8080/",
Password = "youshallnotpass"
}, new DiscordClientWrapper(client));
var serviceProvider = new ServiceCollection()
.AddSingleton<IAudioService, LavalinkNode>()
.AddSingleton<IDiscordClientWrapper, DiscordClientWrapper>();
.AddSingleton(new LavalinkNodeOptions {[...]})
[...]
.BuildServiceProvider();
var audioService = serviceProvider.GetRequiredService<IAudioService>();
// Do not forget disposing the service provider!
Lookup the LavalinkNodeOptions in the application.yml
of your Lavalink Node(s).
Before using the service you have to initialize it, this can be done using the Ready event of your discord client implementation:
client.Ready += () => audioService.InitializeAsync();
// get player
var player = _audioService.GetPlayer<LavalinkPlayer>(guildId)
?? await _audioService.JoinAsync(guildId, voiceChannelId);
// resolve a track from youtube
var myTrack = await _audioService.GetTrackAsync("<search query>", SearchMode.YouTube);
// play track
await player.PlayAsync(myTrack);
For more documentation, see: Lavalink4NET Wiki or you could also take a look at Upcoming Features.
- Newtonsoft.Json (for Payload Serialization)