# vertbot-eris-lavalink

> A Lavalink client for eris modified for my personal needs

Latest version **1.1.0** (published 2021-09-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install vertbot-eris-lavalink
pnpm add vertbot-eris-lavalink
yarn add vertbot-eris-lavalink
bun add vertbot-eris-lavalink
```

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-09-17 |
| First published | 2018-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 36.7 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Kaydax |
| Maintainers | kaydax |

## Links

- npm: https://www.npmjs.com/package/vertbot-eris-lavalink
- Repository: https://github.com/Kaydax/vertbot-eris-lavalink
- Issues: https://github.com/Kaydax/vertbot-eris-lavalink/issues
- npm.io page: https://npm.io/package/vertbot-eris-lavalink

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) ^3.1.0
- [eris](https://npm.io/package/eris.md) github:abalabahaha/eris#dev

## Recent versions

- 1.1.0 (latest) — 2021-09-17
- 1.0.1 — 2018-11-01
- 1.0.0 — 2018-11-01

## README

# vertbot-eris-lavalink

A [Lavalink](https://github.com/Frederikam/Lavalink) client for [eris](https://github.com/abalabahaha/eris)

This is a modified version of [eris-lavalink](https://github.com/briantanner/eris-lavalink) for personal use with my discord bot with modified features.

## Links
- **[Documentation](https://briantanner.github.io/eris-lavalink/)**
- **[Lavalink](https://github.com/Frederikam/Lavalink)**
- **[eris](https://github.com/abalabahaha/eris)**
- **[lavalink.js](https://github.com/briantanner/lavalink.js)** (discord.js port)

## Install
```
# Lavalink v2 and v3
npm install eris-lavalink

# Lavalink v1
npm install eris-lavalink@^0.1.3
```

## New Features

```js
//EQ support:

var bands = [
	{
		"band": 0,
		"gain": 0.25
	}
];
player.setEQ(bands);

//The setEQ function takes a json array that contains objects for each band. The bands range from 0 to 15 and the gain ranges from -0.25 to 1, 0 is the default gain.

//Destroying the player:

player.destroy();

/*
From the Lavalink docs:
"Tell the server to potentially disconnect from the voice server and potentially remove the player with all its data. This is useful if you want to move to a new node for a voice connection. Calling this op does not affect voice state, and you can send the same VOICE_SERVER_UPDATE to a new node."
*/
```

## Implementation

Start by creating the `PlayerManager` and passing a list of nodes and optional list of regions
```js
const { PlayerManager } = require('eris-lavalink');

let nodes = [
	{ host: 'localhost', port: 8080, region: 'eu', password: 'youshallnotpass' }
];

let regions = {
	eu: ['eu', 'amsterdam', 'frankfurt', 'russia', 'hongkong', 'singapore', 'sydney'],
	us: ['us', 'brazil'],
};

if (!(client.voiceConnections instanceof PlayerManager)) {
	client.voiceConnections = new PlayerManager(client, nodes, {
		numShards: shardCount, // number of shards
		userId: userid, // the user id of the bot
		regions: regions,
		defaultRegion: 'eu',
	});
}
```

To resolve a track, use the Lavalink rest api
```js
const superagent = require('superagent');

async function resolveTracks(node, search) {
	try {
		var result = await superagent.get(`http://${node.host}:2333/loadtracks?identifier=${search}`)
			.set('Authorization', node.password)
			.set('Accept', 'application/json');
	} catch (err) {
		throw err;
	}

	if (!result) {
		throw 'Unable play that video.';
	}

	return result.body; // array of tracks resolved from lavalink
}

resolveTracks(node, 'ytsearch:the 30 second video').then(tracks => {
	if (!tracks) {
		// no tracks to play
	}
	// do something with the tracks
})
```

To join and leave voice channels, use the Lavalink client rather than using eris.
```js
// to get or join a channel
function getPlayer(channel) {
	if (!channel || !channel.guild) {
		return Promise.reject('Not a guild channel.');
	}

	let player = client.voiceConnections.get(channel.guild.id);
	if (player) {
		return Promise.resolve(player);
	}

	let options = {};
	if (channel.guild.region) {
		options.region = channel.guild.region;
	}

	return client.joinVoiceChannel(channel.id, options);
}

// play example
getPlayer(channel).then(player => {
	player.play(track); // track is the base64 track we get from Lavalink

	player.on('disconnect', (err) => {
		if (err) {
			// log error
		}
		// do something
	});

	player.on('error', err => {
		// log error and handle it
	});

	player.on('stuck', msg => {
		// track stuck event
	})

	player.once('end', data => {
		// REPLACED reason is emitted when playing without stopping, I ignore these to prevent skip loops
		if (data.reason && data.reason === 'REPLACED') {
			return;
		}

		// start playing the next song
	});
});

// stop example
getPlayer(channel).then(player => {
	player.stop();
	if (leave) {
		// disconnect and leave the channel
		client.leaveVoiceChannel(channel.id);
	}
})
```

**A note on pauses**

When you pause a player, the player will be kept in a paused state until you explicitly call resume or the player is disconnected. Calls to `play` and `stop` won't clear the pause state. `player.paused` can be used to check if the player is in paused state.

---
_Source: https://npm.io/package/vertbot-eris-lavalink · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
