Skip to content

freyacoded/waterlink

 
 

Repository files navigation

waterlink



What is waterlink?

Waterlink is a Lavalink client written in Go. The client is based on Lavalink version 3.0 or higher.


Prerequisites

To use a Go package such as waterlink, you must of course have Go installed on your system.

It is assumed that you have already worked with the Go environment. If this is not the case, see this page first.


Installation

To use waterlink as a Go package, you must have it installed on your current system. If this is not the case, run the command below.

go get -u github.com/lukasl-dev/waterlink

Getting started

Create a Client

The Client is used to connect to the HTTP and Websocket server.

client, err := waterlink.New(
  waterlink.HTTP(":8080"), // HTTP(S) server host address
  waterlink.WS(":8080"), // WS(S) server host address
  waterlink.Password("youshallnotpass"), // server authorisation password
  waterlink.UserID("botID"), // bot's user id
)

// handle error

Load one or more Tracks

See the Track Loading API.

typ, playlist, tracks, err := client.LoadTracks("source")

// handle error

Play a Track

To be able to play music, waterlink must be integrated.

err := client.PlayTrack("guildID", track)

// handle error

Integration

Integrate discordgo

Here it is assumed that you already have experience with the discordgo package. If this is not the case, see this page first.

To be able to play audio, a sessionID is required.

var sessionID string

discord.AddHandler(func(session *discordgo.Session, event *discordgo.Ready) {
  sessionID = event.SessionID
})

To be able to stream audio, the VoiceServerUpdate must be provided. See this.

discord.AddHandler(session *discordgo.Session, event *discordgo.VoiceServerUpdate) {
  err := client.VoiceUpdate(event.GuildID, sessionID, waterlink.VoiceServerUpdate{
    GuildID:  event.GuildID,
    Token:    event.Token,
    Endpoint: event.Endpoint,
  })

  // handle error
}

After discordgo has been integrated, music can be played.

Use the code below to join a guild's voice channel. After that music can be played.

err := dg.ChannelVoiceJoinManual("guildID", "voiceChannelID", false, false)

// handle error