- You need to enable Lavalink on your
DiscordClient
by 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 yourLavalinkExtension
instance. That method returns aLavalinkNodeConnection
instance. - Connect to a voice channel using
.ConnectAsync(voiceChannel)
on yourLavalinkNodeConnection
instance. That method returns aLavalinkGuildConnection
instance, which you will use to control your playback. - Obtain a
LavalinkTrack
using.GetTracksAsync(new Uri("https://www.youtube.com/watch?v=dQw4w9WgXcQ"))
on yourLavalinkNodeConnection
instance. 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.