Azusfin / lavacoffee

A fast and rich-featured lavalink wrapper for node.js
https://Azusfin.github.io/lavacoffee/index.html
BSD 3-Clause "New" or "Revised" License
7 stars 3 forks source link

node error #4

Closed kabirjaipal closed 2 years ago

kabirjaipal commented 2 years ago

bro idk how to add lavalink nodes can you send code example with working lavalink server please bro its so confusing

Azusfin commented 2 years ago

to add node

lava.add({
  name: "unique name for the node"
  url: "lavalink server url",
  password: "lavalink server password",
  secure: false // whether the server allow secure protocol
})

where lava is your lava instance

example with the usual localhost

lava.add({
  name: "lavalink-node-1",
  url: "localhost:2333",
  password: "youshallnotpass",
  secure: false
})

and in the bot ready event (if you use discord.js), the lava instance need to be initialized

client.once("ready", () => lava.init(client.user.id))

raw event also need to be listened to get the voice state and voice server payload

client.on("raw", d => lava.updateVoiceData(d))
kabirjaipal commented 2 years ago

thank you so much

kabirjaipal commented 2 years ago

ready.js  Events Loaded Successfullly
Error: Cannot find module '/home/container/node_modules/lavacoffee/dist/utils/constants'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:960:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:953:15)
    at resolveExports (node:internal/modules/cjs/loader:482:14)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/container/commands/Music/pause.js:9:26)
    at Module._compile (node:internal/modules/cjs/loader:1101:14) {
  code: 'MODULE_NOT_FOUND',
  path: '/home/container/node_modules/lavacoffee/package.json'
}```

fix this please
kabirjaipal commented 2 years ago

when i add new song song will pause next song not playing

Azusfin commented 2 years ago

when i add new song song will pause next song not playing

any code of your play command?

kabirjaipal commented 2 years ago

when i add new song song will pause next song not playing

any code of your play command?

const { Command } = require("reconlx");
const ee = require("../../settings/embed.json");
const config = require("../../settings/config.json");
const manager = require("../../handlers/Lavalink/player");
const emoji = require("../../settings/emoji.json");
const { MessageEmbed } = require("discord.js");
const { LoadTypes } = require("lavacoffee/dist/utils");

module.exports = new Command({
  // options
  name: "play",
  description: `Play Your Fav Song`,
  userPermissions: ["CONNECT"],
  botPermissions: ["CONNECT"],
  category: "Music",
  cooldown: 10,
  options: [
    {
      name: "song",
      description: "give song name or url",
      type: "STRING",
      required: true,
    },
  ],
  // command start
  run: async ({ client, interaction, args, prefix }) => {
    // Code
    let quary = interaction.options.getString("song");
    let botchannel = interaction.guild.me.voice.channel;
    let { channel } = interaction.member.voice;
    if (!channel) {
      return client.embed(
        interaction,
        `${emoji.ERROR} You Need To Join Voice Channel`
      );
    } else if (channel.userLimit !== 0 && channel.full) {
      return client.embed(
        interaction,
        `${emoji.ERROR} Your Voice Channel is Full , i can't Join`
      );
    } else if (botchannel && !botchannel.equals(channel)) {
      return client.embed(
        interaction,
        `You Need to Join ${botchannel} To Listen Song With Me..`
      );
    } else if (interaction.guild.me.voice.serverMute === true) {
      return client.embed(
        interaction,
        `${emoji.ERROR} Sorry, I can't join voice channel , i am muted`
      );
    } else {
      let player = await manager.players.get(interaction.guild.id);
      if (!player) {
        player = await manager.create({
          guildID: interaction.guild.id,
          selfDeaf: true,
          selfMute: false,
          voiceID: channel.id,
          volume: 100,
          metadata: {
            text: interaction.channel,
            voice: channel,
          },
        });
      }

      if (player.voiceState != "Connected") await player.connect();

      await manager
        .search({ query: quary }, interaction.user)
        .then(async (res) => {
          console.log("1");

          switch (res.loadType) {
            case LoadTypes.LoadFailed:
              {
                console.log(`load failed`);
                if (!player.queue.current) player.destroy();
                return client.embed(
                  interaction,
                  `${emoji.ERROR} Search Failed Reason :- \`${res.error.message}\``
                );
              }
              break;
            case LoadTypes.NoMatches:
              {
                console.log(`no match`);
                if (!player.queue.current) player.destroy();
                return client.embed(
                  interaction,
                  `${emoji.ERROR} No Result Found For \`${quary}\``
                );
              }
              break;
            case LoadTypes.SearchResult:
              {
                console.log(`resiilt`);
                let track = res.tracks[0];
                await player.queue.add(track);
                interaction.followUp({
                  embeds: [
                    new MessageEmbed()
                      .setColor(ee.color)
                      .setAuthor({
                        name: `Added to Queue`,
                        iconURL: track.displayThumbnail(),
                        url: track.url,
                      })
                      .setDescription(
                        ` ${emoji.show_queue} [\`${track.title}\`](${track.url}) \n\n Added By: ${track.requester} | Duration: ❯ \`${track.duration}\` | Position In Queue: \`${player.position}\``
                      )
                      .setFooter({
                        text: ee.footertext,
                        iconURL: ee.footericon,
                      }),
                  ],
                });
                if (!player.queue.current) {
                  player.play({}).catch((e) => {});
                }
              }
              break;
            case LoadTypes.TrackLoaded:
              {
                console.log(`loadeds`);

                let track = res.tracks[0];
                await player.queue.add(track);
                interaction.followUp({
                  embeds: [
                    new MessageEmbed()
                      .setColor(ee.color)
                      .setAuthor({
                        name: `Added to Queue`,
                        iconURL: track.displayThumbnail(),
                        url: track.url,
                      })
                      .setDescription(
                        ` ${emoji.show_queue} [\`${track.title}\`](${track.url}) \n\n Added By: ${track.requester} | Duration: ❯ \`${track.duration}\` | Position In Queue: \`${player.position}\``
                      )
                      .setFooter({
                        text: ee.footertext,
                        iconURL: ee.footericon,
                      }),
                  ],
                });
                if (!player.queue.current) {
                  player.play({}).catch((e) => {});
                }
              }
              break;
            case LoadTypes.PlaylistLoaded:
              {
                let playlist = res.playlist;
                await player.queue.add(res.tracks);
                interaction.followUp({
                  embeds: [
                    new MessageEmbed()
                      .setColor(ee.color)
                      .setAuthor({
                        name: `Playlist Added to Queue`,
                        iconURL: playlist.selectedTrack.displayThumbnail(),
                        url: playlist.selectedTrack.url,
                      })
                      .setDescription(
                        ` ${emoji.show_queue} [\`${playlist.name}\`](${playlist.selectedTrack.url}) \n\n Added By: ${playlist.selectedTrack.requester} | Duration: ❯ \`${playlist.duration}\` | Songs : \`${res.tracks.length}\``
                      )
                      .setFooter({
                        text: ee.footertext,
                        iconURL: ee.footericon,
                      }),
                  ],
                });
                if (
                  !player.queue.currentr &&
                  player.queue.totalSize === res.tracks.length
                ) {
                  player.play({}).catch((e) => {});
                }
              }
              break;
            default:
              {
                console.log(`haha`);
              }
              break;
          }
        });
    }
  },
});
Azusfin commented 2 years ago

when i add new song song will pause next song not playing

any code of your play command?

const { Command } = require("reconlx");
const ee = require("../../settings/embed.json");
const config = require("../../settings/config.json");
const manager = require("../../handlers/Lavalink/player");
const emoji = require("../../settings/emoji.json");
const { MessageEmbed } = require("discord.js");
const { LoadTypes } = require("lavacoffee/dist/utils");

module.exports = new Command({
  // options
  name: "play",
  description: `Play Your Fav Song`,
  userPermissions: ["CONNECT"],
  botPermissions: ["CONNECT"],
  category: "Music",
  cooldown: 10,
  options: [
    {
      name: "song",
      description: "give song name or url",
      type: "STRING",
      required: true,
    },
  ],
  // command start
  run: async ({ client, interaction, args, prefix }) => {
    // Code
    let quary = interaction.options.getString("song");
    let botchannel = interaction.guild.me.voice.channel;
    let { channel } = interaction.member.voice;
    if (!channel) {
      return client.embed(
        interaction,
        `${emoji.ERROR} You Need To Join Voice Channel`
      );
    } else if (channel.userLimit !== 0 && channel.full) {
      return client.embed(
        interaction,
        `${emoji.ERROR} Your Voice Channel is Full , i can't Join`
      );
    } else if (botchannel && !botchannel.equals(channel)) {
      return client.embed(
        interaction,
        `You Need to Join ${botchannel} To Listen Song With Me..`
      );
    } else if (interaction.guild.me.voice.serverMute === true) {
      return client.embed(
        interaction,
        `${emoji.ERROR} Sorry, I can't join voice channel , i am muted`
      );
    } else {
      let player = await manager.players.get(interaction.guild.id);
      if (!player) {
        player = await manager.create({
          guildID: interaction.guild.id,
          selfDeaf: true,
          selfMute: false,
          voiceID: channel.id,
          volume: 100,
          metadata: {
            text: interaction.channel,
            voice: channel,
          },
        });
      }

      if (player.voiceState != "Connected") await player.connect();

      await manager
        .search({ query: quary }, interaction.user)
        .then(async (res) => {
          console.log("1");

          switch (res.loadType) {
            case LoadTypes.LoadFailed:
              {
                console.log(`load failed`);
                if (!player.queue.current) player.destroy();
                return client.embed(
                  interaction,
                  `${emoji.ERROR} Search Failed Reason :- \`${res.error.message}\``
                );
              }
              break;
            case LoadTypes.NoMatches:
              {
                console.log(`no match`);
                if (!player.queue.current) player.destroy();
                return client.embed(
                  interaction,
                  `${emoji.ERROR} No Result Found For \`${quary}\``
                );
              }
              break;
            case LoadTypes.SearchResult:
              {
                console.log(`resiilt`);
                let track = res.tracks[0];
                await player.queue.add(track);
                interaction.followUp({
                  embeds: [
                    new MessageEmbed()
                      .setColor(ee.color)
                      .setAuthor({
                        name: `Added to Queue`,
                        iconURL: track.displayThumbnail(),
                        url: track.url,
                      })
                      .setDescription(
                        ` ${emoji.show_queue} [\`${track.title}\`](${track.url}) \n\n Added By: ${track.requester} | Duration: ❯ \`${track.duration}\` | Position In Queue: \`${player.position}\``
                      )
                      .setFooter({
                        text: ee.footertext,
                        iconURL: ee.footericon,
                      }),
                  ],
                });
                if (!player.queue.current) {
                  player.play({}).catch((e) => {});
                }
              }
              break;
            case LoadTypes.TrackLoaded:
              {
                console.log(`loadeds`);

                let track = res.tracks[0];
                await player.queue.add(track);
                interaction.followUp({
                  embeds: [
                    new MessageEmbed()
                      .setColor(ee.color)
                      .setAuthor({
                        name: `Added to Queue`,
                        iconURL: track.displayThumbnail(),
                        url: track.url,
                      })
                      .setDescription(
                        ` ${emoji.show_queue} [\`${track.title}\`](${track.url}) \n\n Added By: ${track.requester} | Duration: ❯ \`${track.duration}\` | Position In Queue: \`${player.position}\``
                      )
                      .setFooter({
                        text: ee.footertext,
                        iconURL: ee.footericon,
                      }),
                  ],
                });
                if (!player.queue.current) {
                  player.play({}).catch((e) => {});
                }
              }
              break;
            case LoadTypes.PlaylistLoaded:
              {
                let playlist = res.playlist;
                await player.queue.add(res.tracks);
                interaction.followUp({
                  embeds: [
                    new MessageEmbed()
                      .setColor(ee.color)
                      .setAuthor({
                        name: `Playlist Added to Queue`,
                        iconURL: playlist.selectedTrack.displayThumbnail(),
                        url: playlist.selectedTrack.url,
                      })
                      .setDescription(
                        ` ${emoji.show_queue} [\`${playlist.name}\`](${playlist.selectedTrack.url}) \n\n Added By: ${playlist.selectedTrack.requester} | Duration: ❯ \`${playlist.duration}\` | Songs : \`${res.tracks.length}\``
                      )
                      .setFooter({
                        text: ee.footertext,
                        iconURL: ee.footericon,
                      }),
                  ],
                });
                if (
                  !player.queue.currentr &&
                  player.queue.totalSize === res.tracks.length
                ) {
                  player.play({}).catch((e) => {});
                }
              }
              break;
            default:
              {
                console.log(`haha`);
              }
              break;
          }
        });
    }
  },
});

!player.queue.currentr

what's with the extra r

you can also look on my bot for example using lavacoffee Music Bot

kabirjaipal commented 2 years ago

but when i skip song nextt songg not playing can you make discord server for support my server https://discord.gg/RRmCm7VBzE

Azusfin commented 2 years ago

but when i skip song nextt songg not playing can you make discord server for support my server https://discord.gg/RRmCm7VBzE

unfortunately, i didn't have a plan for discord server yet, sorry

so when you use skip command then next song won't play?

any code how you construct the lava instance and the skip code?

kabirjaipal commented 2 years ago

lava manager code

const { CoffeeLava } = require("lavacoffee");
const client = require("../../index");

let manager = new CoffeeLava({
  balanceLoad: "lavalink",
  send: (id, p) => {
    let guild = client.guilds.cache.get(id);
    guild.shard.send(p);
  },
  // autoPlay: false,
  // autoReplay: true,
  // autoResume: true,
  // clientName: "op",
});
module.exports = manager;

events code

const { Client } = require("discord.js");
const manager = require("./player");

/**
 *
 * @param {Client} client
 */
module.exports = async (client) => {
  await manager.add({
    name: "lavalink-node-1",
    url: "lava.link:80",
    password: "lava123",
    secure: false,
    retryDelay: Infinity,
  });
  client.once("ready", async () => {
    manager.init(client.user.id);
  });
  client.on("raw", (d) => manager.updateVoiceData(d));

  manager.on("nodeConnect", async (node) => {
    console.log(`Node Connected to ${node.options.name}`);
  });

  manager.on("nodeCreate", async (node) => {
    console.log(`Node Created ${node.options.name}`);
  });

  manager.on("nodeDestroy", async (node) => {
    console.log(`Node Destroyed ${node.options.name}`);
  });

  manager.on("nodeDisconnect", async (node) => {
    console.log(`Node Disconnected ${node.options.name}`);
  });

  manager.on("nodeError", async (node, error) => {
    console.log(`Node Error ${error.message}`);
  });

  manager.on("nodeReconnect", async (node) => {
    console.log(`Node Recconcting ${node.options.name}`);
  });

  manager.on("trackStart", async (player, track) => {
    let channell = await player.get("text");
    channell?.send(`Playing ${track.title}`);
  });

  manager.on("playerDestroy", async (player) => {
    let channell = await player.get("text");
    channell?.send(`Someone disconnected me form Voice Channel`);
  });
};

skipp cmd

const { Command } = require("reconlx");
const ee = require("../../settings/embed.json");
const config = require("../../settings/config.json");
const manager = require("../../handlers/Lavalink/player");
const emoji = require("../../settings/emoji.json");
const { MessageEmbed } = require("discord.js");
const { check_dj } = require("../../handlers/functions");

module.exports = new Command({
  // options
  name: "skip",
  description: `skip current song`,
  userPermissions: ["CONNECT"],
  botPermissions: ["CONNECT"],
  category: "Music",
  cooldown: 10,
  // command start
  run: async ({ client, interaction, args, prefix }) => {
    // Code
    let botchannel = interaction.guild.me.voice.channel;
    let player = await manager.players.get(interaction.guild.id);

    let { channel } = interaction.member.voice;
    if (!channel) {
      return client.embed(
        interaction,
        `${emoji.ERROR} You Need To Join Voice Channel`
      );
    } else if (channel.userLimit !== 0 && channel.full) {
      return client.embed(
        interaction,
        `${emoji.ERROR} Your Voice Channel is Full , i can't Join`
      );
    } else if (botchannel && !botchannel.equals(channel)) {
      return client.embed(
        interaction,
        `You Need to Join ${botchannel} To Listen Song With Me..`
      );
    } else if (interaction.guild.me.voice.serverMute === true) {
      return client.embed(
        interaction,
        `${emoji.ERROR} Sorry, I can't join voice channel , i am muted`
      );
    } else if (check_dj(client, interaction.member, player.queue.current)) {
      return client.embed(
        interaction,
        `${emoji.ERROR} You are not DJ and also you are not song requester..`
      );
    } else {
      await player.stop();
      return client.embed(
        interaction,
        ` ${emoji.skip_track}  Song Skiped by ${interaction.user.tag}`
      );
    }
  },
});

you can join my server for help me https://discord.gg/RRmCm7VBzE i am youtuber i will promote your package

Azusfin commented 2 years ago

code looks good to me, weird to see why it won't play the next song when skipping current song for you

image1 image2

as you can see in image above, it successfully play the next song after skip, so i cant really reproduce it

i might try to join your server later

kabirjaipal commented 2 years ago

but when i skip song socketclosed event fire why ?

Azusfin commented 2 years ago

but when i skip song socketclosed event fire why ?

huh, is the bot disconnected from voice channel?

kabirjaipal commented 2 years ago

but when i skip song socketclosed event fire why ?

huh, is the bot disconnected from voice channel?

no

Azusfin commented 2 years ago

hmm, that's weird

kabirjaipal commented 2 years ago

hmm, that's weird

i got fix i will make a example bot in js can you add ?

Azusfin commented 2 years ago

hmm, that's weird

i got fix i will make a example bot in js can you add ?

that's good then 👍, may i see the example code?

kabirjaipal commented 2 years ago

wait i am coding

kabirjaipal commented 2 years ago

here is exmaple music bot

kabirjaipal commented 2 years ago

https://github.com/kabirsingh2004/lavacoffee-music-bot

filters not working please check

Azusfin commented 2 years ago

explain not working

Azusfin commented 2 years ago

you have player.setFilters([]) in clear command instead of player.setFilters({}) not sure if that's your problem

Azusfin commented 2 years ago

no respond since 🤔

kabirjaipal commented 2 years ago

can you join server we can talk easilly about package https://discord.com/invite/PcUVWApWN3