1.1.0 • Published 11 months ago

lavabeats v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

LavaBeats is the best library for playing and manage your music on Discord with Lavalink's server !

Things required :

A latest version of Java (JDK) for execute your Lavalink's server

Lavalink.jar https://github.com/lavalink-devs/Lavalink/tags

FOR HELP: https://discord.gg/tSHCBKhYc8

Official support of Lavalink: https://discord.gg/lavalink-1082302532421943407

Create your 'application.yml' for Config your Lavalink's server

BEFORE EXECUTE YOUR BOT, EXECUTE THE LAVALINK'S SERVER

Libraries we support: ALL (Discord.JS, ERIS...)

Example code Bot (Discord.js)

const { Client } = require('discord.js');
const { LavaBeats } = require('lavabeats');

const client = new Client({intents: 3276799}); //All intents
client.login("TOKEN DISCORD BOT");

client.on('ready', () => {
  console.log(client.user.tag);
  client.music = new LavaBeats(client, [{
    host: "localhost",
    password: "LAVABEATS_PASSWORD", //PASSWORD CONFIGURED ON application.yml
    port: 2635, //PORT CONFIGURED ON application.yml
    secure: false
  }], { 
    send: (payload) => {
      const guild = client.guilds.cache.get(payload.d.guild_id);
      if(guild) guild.shard.send(payload);
      /*Update this function if your library don't work with LavaBeats*/
    }
  });

  client.on("raw", (d) => client.music?.updateVoiceState(d));
  client.music.init(client.user.id);
  client.music.on('nodeConnect', async () => {
    console.log("Node connected !");

    //If you want to configure a poToken as well as visitorData to properly use the YouTube plugin, use this request:
    client.music.nodeMap.get(/*YOUR CURRENT NODE*/).rest.updateYoutubePluginData("your poToken", "your visitorData")
  }); //If you don't have this log, start your Lavalink.jar (and if you have already start Lavalink, check the console of Lavalink for get the errors)
  client.music.on('trackStart', (player, track) => client.channels.cache.get(player.textChannel)?.send(`:crystal_ball: New Music Started!\n\n- ${track.info.author}\n- ${track.info.title} [MUSIC HERE](${track.info.uri})`)); //Not required
  client.music.on('queueEnd', player => {
    player.destroy();
    return client.channels.cache.get(player.textChannel)?.send("Queen has ended. (I leave the voice channel)");
  }); //Not required
});

Exemple of multiple commands:

client.on('messageCreate', async message => {
  if(!message.guild || !message.member || !message.content) return;

  const args = message.content.split(' ');
  if(!args) return;

  const commandName = args.shift()?.toLowerCase();
  if(!commandName) return;

  if(commandName === "!play") {
    if(!message.member.voice.channel) return message.reply(":x: Please join a voice channel !");

    const music = args.join(" ");
    let source = "ytmsearch:";

    if(/^(https?:\/\/)?(www\.)?(youtube\.com\/|youtu\.be\/)/.test(music)) source = ""; //If is YouTube URL, Lavalink can't found with "ytsearch: or ytmsearch:"
    if(/https?:\/\/(www\.)?open\.spotify\.com\/[^\s]*/g.test(music)) source = "ytmsearch:"; //If is Spotify URL, the source search method is set on defaultSearchPlateform.spotify

    return await client.music.search({
      query: music,
      requester: message.author,
      source: source
    }).then(musicSearch => {
      if(!musicSearch || !musicSearch.tracks) return message.reply(":x: No music found !");
      if(musicSearch.tracks) {
        const player = client.music.players.get(message.guild.id) || client.music.createConnection({
          guildId: message.guild.id,
          voiceChannel: message.member.voice.channel.id,
          textChannel: message.channel.id,
          deaf: true
        });

        player.queue.push(musicSearch.tracks[0]);
        if(!player.playing) player.play();

        return message.reply(`:notes: Music added to queue!\n- ${musicSearch.tracks[0].info.author}\n- ${musicSearch.tracks[0].info.title} [MUSIC HERE](${musicSearch.tracks[0].info.uri})`);
      };
    });
  };

  if(commandName === "!playlist") {
    if(!message.member.voice.channel) return message.reply(":x: Please join a voice channel !");
    
    const playlist = args[0];
    if(!playlist) return message.reply(":x: No playlist specified!");

    let source = null;
    if(/^(https?:\/\/)?(www\.)?(youtube\.com\/|youtu\.be\/)/.test(playlist)) source = ""; //If is YouTube URL, Lavalink can't found with "ytsearch: or ytmsearch:"
    if(/https?:\/\/(www\.)?open\.spotify\.com\/[^\s]*/g.test(playlist)) source = "ytmsearch:"; //If is Spotify URL, the source search method is set on defaultSearchPlateform.spotify

    if(source === null) return message.reply(":x: No valid playlist specified!");

    return await client.music.search({
      query: playlist,
      requester: message.author,
      source: source
    }).then(musicSearch => {
      if(!musicSearch || !musicSearch.tracks) return message.reply(":x: No music found !");
      if(musicSearch.tracks && musicSearch.tracks.length > 1) {
        const player = client.music.players.get(message.guild.id) || client.music.createConnection({
          guildId: message.guild.id,
          voiceChannel: message.member.voice.channel.id,
          textChannel: message.channel.id,
          deaf: true
        });

        musicSearch.tracks?.forEach(music => player.queue.push(music));
        if(!player.playing) player.play();

        return message.reply(`:scroll: The playlist ${musicSearch.playlistInfo.name} has been load!\n${musicSearch.tracks.length} musics add!`);
      };
    });
  };

  if(commandName === "!skip") {
    if(!message.member.voice.channel) return message.reply(":x: Please join a voice channel !");
    
    const player = client.music.players.get(message.guild.id);
    if(!player || !player.queue.length) return message.reply(":x: No Music available !");

    player.stop();
    return message.reply(`:skip: Music skipped!\n- ${player.current.info.author}\n- [${player.current.info.title}](${player.current.info.uri})`);
  };

  if(commandName === "!leave") {
    if(!message.member.voice.channel) return message.reply(":x: Please join a voice channel !");

    const player = client.music.players.get(message.guild.id);
    if(!player || !player.current) return message.reply(":x: No Player available!");

    player.destroy();
    return message.reply(':white_check_mark: Leaving the voice channel !');
  };

  if(commandName === "!pause") {
    if(!message.member.voice.channel) return message.reply(":x: Please join a voice channel !");

    const player = client.music.players.get(message.guild.id);
    if(!player || !player.current) return message.reply(":x: No Player available!");

    const options = args[0];
    if(!options || !["on", "off"].includes(options)) return message.reply(":x: Please include a option. (on/off)");

    player.setPause(options === "on");
    return message.reply(`:white_check_mark: The music is ${options === "on" ? "paused" : "unpaused"} !`);
  };

  if(commandName === "!volume") {
    if(!message.member.voice.channel) return message.reply(":x: Please join a voice channel !");

    const player = client.music.players.get(message.guild.id);
    if(!player || !player.current) return message.reply(":x: No Player available!");

    const options = parseInt(args[0]);
    if(!options || isNaN(parseInt(args[0])) || options < 1 || options > 1000) return message.reply(":x: Please specified a new volume. (1-1000)");

    player.setVolume(options);
    return message.reply(`:white_check_mark: The volume is on ${options}/1000`);
  };

  if(commandName === "!filter") {
    if(!message.member.voice.channel) return message.reply(":x: Please join a voice channel !");

    const player = client.music.players.get(message.guild.id);
    if(!player || !player.current) return message.reply(":x: No Player available!");

    const filter = args[0];
    if(!filter) return message.reply(":x: No filter specified !");

    const enable_filter = args[1];
    if(!enable_filter || !["on", "off"].includes(enable_filter)) return message.reply(":x: Please include a option. (on/off)");

    const newFilter = player.filters.setFilter(filter, enable_filter === "on");
    if(!newFilter) return message.reply(':x: The specified filter is invailable!');

    return message.reply(`:white_check_mark: The filter ${filter} is ${enable_filter === "on" ? "now used" : "not used"} !`);
  }; //Filters options: ["karaoke", "timescale", "tremolo", "vibrato", "rotation", "distortion", "channelMix", "lowPass", "bassboost", "slowmode", "nightcore", "vaporwave", "8d"]

  if(commandName === "!repeat") {
    if(!message.member.voice.channel) return message.reply(":x: Please join a voice channel !");

    const player = client.music.players.get(message.guild.id);
    if(!player || !player.current) return message.reply(":x: No Player available!");

    const loopOption = args[0];
    if(!loopOption || !["track", "queue", "none"].includes(loopOption)) return message.reply(":x: No repeat option specified !"); //track = actual song/queue = all queue/none = disabled
    player.setLoop(loopOption);

    return message.reply(`:white_check_mark: The loop option is set on ${loopOption} !`);
  };

  if(commandName === "!lyrics") {
    if(!message.member.voice.channel) return message.reply(":x: Please join a voice channel !");

    const player = client.music.players.get(message.guild.id);
    if(!player || !player.current) return message.reply(":x: No Player available!");
    
    const lyrics = await player.getLyrics(message.guild.id);
    console.log(lyrics)
    if(lyrics && lyrics.text) return message.reply(lyrics.text.slice(0, 2000)); //console.log(lyrics) (is possible get the time for track in direct the lyrics)
    
    return message.reply(`:x: No lyrics found!`);
  };
});

Options available but not created to !command

/* All options player.queue = [] //All pending music will be in this list. (Useful for making a !queue command) player.current = {} //The current music (Useful for making a !current command) player.seek(NUMBER) //Edit the position of the music (NUMBER based on seconds) EX: (15) = 0:15 seconds

use console.log(player) for fetch all data and create yours commands */

1.1.0

11 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago