A powerful discord music library written in TypeScript for Node.js. Support youtube links.
Version 16.6.0 or newer of Node.js is required
Ensure that discord.js and @discordjs/voice have been installed before installing this library
npm install @discordx/music
yarn add @discordx/music
Note: Create a pull request to include your bot in the example list.
const player = new Player();
const queue = player.queue(interaction.guild);
await queue.join(interaction.member.voice.channel);
const status = await queue.play(songName);
if (!status) {
interaction.followUp("The song could not be found");
} else {
interaction.followUp("The requested song is being played");
}
const status = await queue.playlist(playlistLink);
if (!status) {
interaction.followUp("The playlist could not be found");
} else {
interaction.followUp("playing requested playlist");
}
const audioPlayer = queue.audioPlayer;
const voiceConnection = queue.voiceConnection;
const voiceChannelId = queue.voiceChannelId;
const voiceGroup = queue.voiceGroup;
const voiceGuildId = queue.voiceGuildId;
const tracks = queue.tracks;
const state = queue.loop;
queue.setLoop(true | false);
const state = queue.repeat;
queue.setRepeat(true | false);
queue.pause();
queue.resume();
queue.skip();
queue.leave();
queue.mix();
queue.playbackDuration;
queue.volume;
queue.setVolume(volume: number);
queue.seek(time: number);
queue.clearTracks();
queue.removeTracks([1, 3, 5]);
const total = queue.size;
this.player.on("onError", console.log);
this.player.on("onFinish", console.log);
this.player.on("onStart", console.log);
this.player.on("onLoop", console.log);
this.player.on("onFinishPlayback", console.log);
this.player.on("onRepeat", console.log);
this.player.on("onSkip", console.log);
this.player.on("onPause", console.log);
this.player.on("onResume", console.log);
this.player.on("onTrackAdd", console.log);
this.player.on("onLoopEnabled", console.log);
this.player.on("onLoopDisabled", console.log);
this.player.on("onRepeatEnabled", console.log);
this.player.on("onRepeatDisabled", console.log);
this.player.on("onMix", console.log);
this.player.on("onVolumeUpdate", console.log);
this.player.on("onSeek", console.log);
this.player.on("onJoin", console.log);
this.player.on("onLeave", console.log);
class MyQueue extends Queue {
customProp = "custom queue";
}
Tell the player to use this custom queue
class MyQueue extends Queue {}
this.player.queue(guild, () => new MyQueue(this.player, guild));
class MyPlayer extends Player {
// custom player
}
Let your queue know about custom player
const myQueue: Queue<MyPlayer> = new Queue(this, guild);
const node = new Lava.Node({
host: {
address: process.env.LAVA_HOST ?? "",
port: Number(process.env.LAVA_PORT) ?? 2333,
},
// your Lavalink password
password: process.env.LAVA_PASSWORD ?? "",
send(guildId, packet) {
const guild = client.guilds.cache.get(guildId);
if (guild) {
guild.shard.send(packet);
}
},
shardCount: 0, // the total number of shards that your bot is running (optional, useful if you're load balancing)
userId: client.user?.id ?? "", // the user id of your bot
});
client.ws.on("VOICE_STATE_UPDATE", (data: Lava.VoiceStateUpdate) => {
node.voiceStateUpdate(data);
});
client.ws.on("VOICE_SERVER_UPDATE", (data: Lava.VoiceServerUpdate) => {
node.voiceServerUpdate(data);
});
const player = node.players.get("guild id");
await player.join("channel id");
const res = await voice.load("ytsearch:monstercat");
await player.play(res.tracks[0]);
await player.stop();
// or, to destroy the player entirely
await player.destroy();
const cluster = new Lava.Cluster({
nodes: [
// node options here; see above
],
send(guildId, packet) {
// send to gateway; same as for single node usage
},
filter(node, guildId) {
// optional
// return a boolean indicating whether the given guild can be run on the given node
// useful for limiting guilds to specific nodes (for instance, if you setup lavalink edge servers to minimize latency)
// this must return true at least once for a given set of nodes, otherwise some methods may error
},
});
- Check frequently asked questions
- Check examples
- Ask in the community Discord server