- You need to enable Lavalink on your
DiscordClientby calling.UseLavalink(). This method returns an instance ofLavalinkExtension. - Create an instance of Lavalink configuration for your Lavalink node:
var lavaconfig = new LavalinkConfiguration { RestEndpoint = new ConnectionEndpoint { Hostname = "localhost", Port = 2333 }, SocketEndpoint = new ConnectionEndpoint { Hostname = "localhost", Port = 80 }, Password = "youshallnotpass" } // replace the ports and the password with the values from your lavalink's application.yml
- Connect to your lavalink node using
.ConnectAsync(lavaconfig)on yourLavalinkExtensioninstance. That method returns aLavalinkNodeConnectioninstance. - Connect to a voice channel using
.ConnectAsync(voiceChannel)on yourLavalinkNodeConnectioninstance. That method returns aLavalinkGuildConnectioninstance, which you will use to control your playback. - Obtain a
LavalinkTrackusing.GetTracksAsync(new Uri("https://www.youtube.com/watch?v=dQw4w9WgXcQ"))on yourLavalinkNodeConnectioninstance. This will return a collection of tracks (or a single track). Grab the.First()track. - Call
.Play(track)on yourLavalinkGuildConnection.
To pause you call .Pause(), to resume you call .Resume(), to stop you call .Stop(), to seek you call .Seek(TimeSpan position), to change volume you call .SetVolume(int volume). You can obtain information about current track by retrieving .CurrentState property of your guild connection, and resource usage infromation by retrieving .Statistics property of your node connection.
To disconnect from voice channel, simply call .Disconnect() on your guild connection, and to disconnect from your node, call .StopAsync() on your node connection.
You can connect to multiple nodes, each one will use its own node connection instance, and each guild will have its own guild connection instance.
More specifically, you obtain IEnumerable using .GetTracksAsync, and then you use that IEnumerable of LavalinkTracks to obtain a LavalinkTrack. This step confused me, so I figured I'd mention it for other newbs.