Skip to content

Lavalink4NET is a Lavalink wrapper with node clustering, caching and custom players for .NET with support for Discord.Net and DSharpPlus.

License

Notifications You must be signed in to change notification settings

freyacoded/Lavalink4NET

 
 

Repository files navigation

CodeFactor.io GitHub tag (latest SemVer) GitHub issues Azure DevOps builds (branch)

Lavalink4NET is a Lavalink wrapper with node clustering, caching and custom players for .NET with support for Discord.Net and DSharpPlus.

Features

  • 🔌 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...

NuGet

Prerequisites

  • One or more Lavalink Nodes
  • .NET Core >= 2.0

Getting Started

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.
Using the constructor

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));
Usage with Dependency Injection / IoC (recommended)
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).

Initializing the node

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();
Joining a voice channel and playing a track
// 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.


Dependencies

About

Lavalink4NET is a Lavalink wrapper with node clustering, caching and custom players for .NET with support for Discord.Net and DSharpPlus.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%