Lavalink4NET is a Lavalink wrapper with node clustering, caching and custom players for .NET with support for Discord.Net and DSharpPlus.
and a lot more...
You can use Lavalink4NET in 3 different modes: Cluster, Node and Rest.
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<LavalinkPlayer>(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.