Ecliptia / moonlink.js

MoonLink.js is a simple package for lavalink client, perfect for you to create your discord bot with songs, and very simple and easy to use.
https://moonlink.js.org
Open Software License 3.0
62 stars 10 forks source link

(Bug): player.connect is broken #119

Open NekoSuneVR opened 6 days ago

NekoSuneVR commented 6 days ago

connect system is broken as wont connect to bot to voice channel, I tried multi bots at once and same issue.

i feeling code needs be updated fix connect sector and on latest as v4.0.2

there is no errors or anything about connecting part continues play musics when not in any voice channels

1Lucas1apk commented 6 days ago

Could you provide the code you are making this connection?

NekoSuneVR commented 6 days ago

i copyed same as template you have so basely same layout as example

just wont reach player.connect() part make it join voice channel

1Lucas1apk commented 6 days ago

the sendPayload part is present in the code, and checked if it is correct for the discord client library you are using

NekoSuneVR commented 6 days ago

im just using discordjs as base code normal lavalink erela.js uses basecode of discordjs but I know that 1 works but that's only for lavalink v3 because stopped updating so that why I was trying move to v4 lavalink get updated code out but I came cross this 1 supports v4 version

but like I say something do with player.connect() wont fire code all rest works I think. because plays music as says chat just no voice joining so cant confirm music working too

1Lucas1apk commented 6 days ago

Could you contact the support server, it would be better to talk

NekoSuneVR commented 6 days ago

im maxed discord server so i cant do threw discord support, that's why did it here

1Lucas1apk commented 6 days ago

Could you provide me with screenshorts or the code itself to know how you are doing it?

1Lucas1apk commented 6 days ago

gives main class Manager, and the connect part

NekoSuneVR commented 6 days ago
const { getGuildToggle } = require("../../utils/funt-ext.js");
const {
  EmbedBuilder,
  PermissionFlagsBits,
  ApplicationCommandType,
  ApplicationCommandOptionType
} = require("discord.js");

function isSpotifyURL(input) {
  try {
    const url = new URL(input);
    return url.hostname === "open.spotify.com";
  } catch (error) {
    return false;
  }
}

module.exports = {
  name: "play",
  description: "Play Music From Spotify",
  type: ApplicationCommandType.ChatInput,
  toggleOff: false,
  developersOnly: false,
  patreonOnly: false,
  patreonManualWhitelist: [
    "1054148043781451776",
    "540706221645103104",
    "100463282099326976",
    "124495978962092037",
    "901415888060825681",
    "588083360598065193",
    "342864764579610626",
    "506525503960776725",
    "191671340149899264",
    "96669710568951808"
  ],
  userpermissions: [
    PermissionFlagsBits.SendMessages,
    PermissionFlagsBits.ViewChannel
  ],
  botpermissions: [
    PermissionFlagsBits.Connect,
    PermissionFlagsBits.Speak,
    PermissionFlagsBits.SendMessages,
    PermissionFlagsBits.ViewChannel
  ],
  cooldowns: 2000,
  options: [
    {
      name: "q",
      description: "Spotify URL or Song Name - Title",
      type: ApplicationCommandOptionType.String,
      required: true
    }
  ],

  run: async (client, interaction) => {
    const [guildsettingstoggle] = await getGuildToggle(interaction.guild.id).catch(console.error);

    if (guildsettingstoggle.musicToggle === 0) {
      return interaction.reply(
        "Server Administrator Disabled Music Integration on this Server. Please go to our Dashboard to re-enable it."
      );
    }

    await interaction.deferReply({ ephemeral: false });

    const query = interaction.options.getString("q");

    /*if (!isSpotifyURL(query)) {
      return interaction.editReply("Only Spotify URLs are allowed.");
    }*/

    if (!interaction.member.voice.channel) {
        return interaction.editReply({
            content: `Error: You must be in a voice channel to execute this command.`,
            ephemeral: true
        });
    }

    const player = client.manager.createPlayer({
        guildId: interaction.guild.id,
        voiceChannelId: interaction.member.voice.channel.id,
        textChannelId: interaction.channel.id,
        autoPlay: true
    });

    if (!player.connected) {
        player.connect({
            setDeaf: true, // Deafens the bot upon joining
            setMute: false // Ensures the bot isn't muted
        });
    }

    await interaction.editReply(`🔍 **Searching...** \`${query}\``);

    const res = await client.manager.search({
        query,
        requester: interaction.user.id
    });

    if (res.loadType === "loadfailed") {
        return interaction.editReply({
            content: `Error: Failed to load the requested track.`,
            ephemeral: true
        });
    } else if (res.loadType === "empty") {
        return interaction.editReply({
            content: `Error: No results found for the query.`,
            ephemeral: true
        });
    }

    if (res.loadType === "playlist") {
        interaction.editReply({
            content: `Playlist ${res.playlistInfo.name} has been added to the queue.`
        });

        for (const track of res.tracks) {
            player.queue.add(track); // Add all tracks from the playlist to the queue
        }
    } else {
        player.queue.add(res.tracks[0]); // Add the first track from the search results
        interaction.editReply({
            content: `Track added to the queue: ${res.tracks[0].title}`
        });
    }

    if (!player.playing) {
        player.play(); // Start playing if not already doing so
    }
  }
};

like I say all rest base code from your example in direct path

only made as command file that's what basely layout you have in example

NekoSuneVR commented 6 days ago

just if (!player.connected) { player.connect({ setDeaf: true, // Deafens the bot upon joining setMute: false // Ensures the bot isn't muted }); } wont fire as example code did

1Lucas1apk commented 6 days ago

and the Manager class

NekoSuneVR commented 6 days ago

manager class is default as yours have example. nothing new then just changing client.manager part because rest my code runs as that


// ———————————————[Music Player]———————————————
const { Manager } = require("moonlink.js");

client.manager = new Manager({
   nodes: client.config.lavalinknodes,
   options: {},
   sendPayload: (guildId, payload)  => {
      const guild = client.guilds.cache.get(guildId);
      if (guild) guild.shard.send(payload); // Sending data to the shard if the guild is available
   }
});

client.on('ready', () => {
   client.manager.init(client.user.id);
 });

 client.on('raw', (d) => client.manager.packetUpdate(d));

// Event: When a node is successfully created and connected
client.manager.on("nodeCreate", node => {
   console.log(`${node.host} was connected`);
});

// Event: When a track starts playing
client.manager.on("trackStart", async (player, track) => {
   client.channels.cache
       .get(player.textChannelId)
       .send(`Now playing: ${track.title}`);
});

// Event: When a track finishes playing
client.manager.on("trackEnd", async (player, track) => {
   client.channels.cache
       .get(player.textChannelId)
       .send(`Track ended: ${track.title}`);
});

client.manager.on("nodeError", (node, error) => {
  // Check if the error message contains 'Unexpected op "ready"'
  if (
    error &&
    error.message &&
    error.message.includes('Unexpected op "ready"')
  ) {
    return; // Ignore the error and do nothing
  }
  console.log(
    `Node "${node.options.identifier}" encountered an error: `,
    error
  );
});

client.manager.on("trackStart", (player, track) => {
  const channel = client.channels.cache.get(player.textChannel);
  channel.send(`Now playing: ${track.title}`);
});

// Reconnection logic for Lavalink nodes
client.manager.on("nodeDisconnect", (node, reason) => {
  console.error(`Node disconnected! Reason: `, reason);

  const reconnectInterval = 60000; // Time in MS, change as needed.

  if (reason !== "RECONNECTED") {
    console.log(`Reconnecting in ${reconnectInterval / 1000} seconds...`);
    setTimeout(() => {
      node.connect();
    }, reconnectInterval);
  }
});```
NekoSuneVR commented 6 days ago

i went back old code had test something v4 so redo code from your codebase

NekoSuneVR commented 6 days ago

like i mention basely round your example code nothing new

1Lucas1apk commented 6 days ago

a common error, just change this here and it should solve the problem

sendPayload: (guildId, payload) => {
    const guild = client.guilds.cache.get(guildId);
    if (guild) guild.shard.send(JSON.parse(payload));
  },
NekoSuneVR commented 6 days ago

i give try see fix

NekoSuneVR commented 6 days ago

now it connects but issue now music wont play image but no error logs

NekoSuneVR commented 6 days ago

just strights connects voice channel then refuses play music

1Lucas1apk commented 6 days ago

Could you send the lavalink logs?

NekoSuneVR commented 6 days ago
lavalinkv4  | 2024-10-15T17:34:08.986Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.player.AudioLoaderRestHandler   : Got request to load for identifier "ytsearch:The Partysquad - Oh My (Dimitri K Remix)"
lavalinkv4  | 2024-10-15T17:34:09.515Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.player.AudioLoaderRestHandler   : Loaded playlist Search results for: The Partysquad - Oh My (Dimitri K Remix)
lavalinkv4  | 2024-10-15T17:34:09.521Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : GET /v4/loadtracks?identifier=ytsearch%3AThe+Partysquad+-+Oh+My+%28Dimitri+K+Remix%29
lavalinkv4  | 2024-10-15T17:34:09.592Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/dvr4vkzavgkfujh0/players/718534469778145320, payload={"track":{"encoded":"QAAA8QMAT1RoZSBQYXJ0eXNxdWFkICYgUGF1bCBFbHN0YWsg4oCTIE9oIE15IChEaW1pdHJpIEsgUmVtaXgpIFtPZmZpY2lhbCBNdXNpYyBWaWRlb10AEFNwaW5uaW4nIFJlY29yZHMAAAAAAAJZkAALeDBVOFMzNW1tMzgAAQAraHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj14MFU4UzM1bW0zOAEANGh0dHBzOi8vaS55dGltZy5jb20vdmkveDBVOFMzNW1tMzgvbWF4cmVzZGVmYXVsdC5qcGcAAAd5b3V0dWJlAAAAAAAAAAA="},"volume":80}

all its says because i using Dockge system

NekoSuneVR commented 6 days ago

this on V4 Lavalink not V3

1Lucas1apk commented 6 days ago

Is client.manager.packetUpdate present in your code?

NekoSuneVR commented 6 days ago

in client.on('raw', (d) => client.manager.packetUpdate(d));

1Lucas1apk commented 6 days ago

Can you provide me with all the lavalink logs?

NekoSuneVR commented 6 days ago

already have thats only data i have doesn't dump any actual logs coz of dockge program I use link multi nodes into 1 little like portcontainer but free version as ultimate device activation

lavalinkv4  | 2024-10-15T17:34:08.986Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.player.AudioLoaderRestHandler   : Got request to load for identifier "ytsearch:The Partysquad - Oh My (Dimitri K Remix)"
lavalinkv4  | 2024-10-15T17:34:09.515Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.player.AudioLoaderRestHandler   : Loaded playlist Search results for: The Partysquad - Oh My (Dimitri K Remix)
lavalinkv4  | 2024-10-15T17:34:09.521Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : GET /v4/loadtracks?identifier=ytsearch%3AThe+Partysquad+-+Oh+My+%28Dimitri+K+Remix%29
lavalinkv4  | 2024-10-15T17:34:09.592Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/dvr4vkzavgkfujh0/players/718534469778145320, payload={"track":{"encoded":"QAAA8QMAT1RoZSBQYXJ0eXNxdWFkICYgUGF1bCBFbHN0YWsg4oCTIE9oIE15IChEaW1pdHJpIEsgUmVtaXgpIFtPZmZpY2lhbCBNdXNpYyBWaWRlb10AEFNwaW5uaW4nIFJlY29yZHMAAAAAAAJZkAALeDBVOFMzNW1tMzgAAQAraHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj14MFU4UzM1bW0zOAEANGh0dHBzOi8vaS55dGltZy5jb20vdmkveDBVOFMzNW1tMzgvbWF4cmVzZGVmYXVsdC5qcGcAAAd5b3V0dWJlAAAAAAAAAAA="},"volume":80}

all its says because i using Dockge system

but does see song as see self

1Lucas1apk commented 6 days ago

these logs are a bit irrelevant to what I want to find, that's why I want the complete logs

NekoSuneVR commented 6 days ago

i dont know where logs file stored for dockge is issue. its still new program release

NekoSuneVR commented 6 days ago

i rebooted it see i dump full logs all I got

lavalinkv4  | Picked up _JAVA_OPTIONS: -Xmx1G
lavalinkv4  | 2024-10-15T17:51:06.564Z  INFO 1 --- [Lavalink] [           main] lavalink.server.Launcher                 : Starting Launcher v4.0.8 using Java 18.0.2.1 with PID 1 (/opt/Lavalink/Lavalink.jar started by lavalink in /opt/Lavalink)
lavalinkv4  | 2024-10-15T17:51:06.573Z  INFO 1 --- [Lavalink] [           main] lavalink.server.Launcher                 : No active profile set, falling back to 1 default profile: "default"
lavalinkv4  | 2024-10-15T17:51:14.232Z  INFO 1 --- [Lavalink] [           main] l.server.bootstrap.PluginManager         : Found plugin 'lavasearch-plugin' version 1.0.0
lavalinkv4  | 2024-10-15T17:51:14.240Z  INFO 1 --- [Lavalink] [           main] l.server.bootstrap.PluginManager         : Found plugin 'lavasrc-plugin' version 4.3.0
lavalinkv4  | 2024-10-15T17:51:14.527Z  INFO 1 --- [Lavalink] [           main] l.server.bootstrap.PluginManager         : Loaded lavasearch-plugin-1.0.0.jar (20 classes)
lavalinkv4  | 2024-10-15T17:51:15.460Z  INFO 1 --- [Lavalink] [           main] l.server.bootstrap.PluginManager         : Loaded lavasrc-plugin-4.3.0.jar (168 classes)
lavalinkv4  | 2024-10-15T17:51:17.157Z  INFO 1 --- [Lavalink] [           main] lavalink.server.Launcher                 : Started Launcher in 13.87 seconds (process running for 20.459)
lavalinkv4  | 2024-10-15T17:51:17.948Z  INFO 1 --- [Lavalink] [           main] lavalink.server.Launcher                 : 
lavalinkv4  | 
lavalinkv4  |        .   _                  _ _       _    __ _ _
lavalinkv4  |       /\\ | | __ ___   ____ _| (_)_ __ | | __\ \ \ \
lavalinkv4  |      ( ( )| |/ _` \ \ / / _` | | | '_ \| |/ / \ \ \ \
lavalinkv4  |       \\/ | | (_| |\ V / (_| | | | | | |   <   ) ) ) )
lavalinkv4  |        '  |_|\__,_| \_/ \__,_|_|_|_| |_|_|\_\ / / / /
lavalinkv4  |     =========================================/_/_/_/
lavalinkv4  | 
lavalinkv4  |   Version:        4.0.8
lavalinkv4  |   Build time:     20.09.2024 20:20:10 UTC
lavalinkv4  |   Branch          HEAD
lavalinkv4  |   Commit:         2946608
lavalinkv4  |   Commit time:    20.09.2024 20:17:58 UTC
lavalinkv4  |   JVM:            18.0.2.1
lavalinkv4  |   Lavaplayer      2.2.2
lavalinkv4  | 
lavalinkv4  | 2024-10-15T17:51:18.034Z  INFO 1 --- [Lavalink] [           main] lavalink.server.Launcher                 : No active profile set, falling back to 1 default profile: "default"
lavalinkv4  | 2024-10-15T17:51:23.878Z  WARN 1 --- [Lavalink] [           main] io.undertow.websockets.jsr               : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
lavalinkv4  | 2024-10-15T17:51:24.053Z  INFO 1 --- [Lavalink] [           main] io.undertow.servlet                      : Initializing Spring embedded WebApplicationContext
lavalinkv4  | 2024-10-15T17:51:24.055Z  INFO 1 --- [Lavalink] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5993 ms
lavalinkv4  | 2024-10-15T17:51:24.717Z  INFO 1 --- [Lavalink] [           main] c.g.t.lavasrc.plugin.LavaSrcPlugin       : Loading LavaSrc plugin...
lavalinkv4  | 2024-10-15T17:51:24.837Z  INFO 1 --- [Lavalink] [           main] c.s.d.l.tools.GarbageCollectionMonitor   : GC monitoring enabled, reporting results every 2 minutes.
lavalinkv4  | 2024-10-15T17:51:26.808Z  WARN 1 --- [Lavalink] [           main] l.s.config.AudioPlayerConfiguration      : The default Youtube source is now deprecated and won't receive further updates.
lavalinkv4  | You should use the new Youtube source plugin instead.
lavalinkv4  | https://github.com/lavalink-devs/youtube-source#plugin.
lavalinkv4  | To disable this warning, set 'lavalink.server.sources.youtube' to false in your application.yml.
lavalinkv4  | 2024-10-15T17:51:30.785Z  INFO 1 --- [Lavalink] [           main] l.server.config.KoeConfiguration         : OS: LINUX, Arch: X86_64
lavalinkv4  | 2024-10-15T17:51:30.800Z  INFO 1 --- [Lavalink] [           main] l.server.config.KoeConfiguration         : Enabling JDA-NAS
lavalinkv4  | 2024-10-15T17:51:30.812Z  INFO 1 --- [Lavalink] [           main] c.s.l.c.natives.NativeLibraryLoader      : Native library udpqueue: loading with filter null
lavalinkv4  | 2024-10-15T17:51:30.839Z  INFO 1 --- [Lavalink] [           main] c.s.l.c.natives.NativeLibraryLoader      : Native library udpqueue: successfully loaded.
lavalinkv4  | 2024-10-15T17:51:31.178Z  WARN 1 --- [Lavalink] [           main] l.server.config.SentryConfiguration      : Turning off sentry
lavalinkv4  | 2024-10-15T17:51:33.251Z  INFO 1 --- [Lavalink] [           main] io.undertow                              : starting server: Undertow - 2.3.13.Final
lavalinkv4  | 2024-10-15T17:51:33.361Z  INFO 1 --- [Lavalink] [           main] org.xnio                                 : XNIO version 3.8.8.Final
lavalinkv4  | 2024-10-15T17:51:33.386Z  INFO 1 --- [Lavalink] [           main] org.xnio.nio                             : XNIO NIO Implementation Version 3.8.8.Final
lavalinkv4  | 2024-10-15T17:51:34.185Z  INFO 1 --- [Lavalink] [           main] org.jboss.threads                        : JBoss Threads version 3.5.0.Final
lavalinkv4  | 2024-10-15T17:51:34.339Z  INFO 1 --- [Lavalink] [           main] o.s.b.w.e.undertow.UndertowWebServer     : Undertow started on port 2333 (http) with context path '/'
lavalinkv4  | 2024-10-15T17:51:34.356Z  INFO 1 --- [Lavalink] [           main] lavalink.server.Launcher                 : Started Launcher in 17.126 seconds (process running for 37.659)
lavalinkv4  | 2024-10-15T17:51:34.358Z  INFO 1 --- [Lavalink] [           main] lavalink.server.Launcher                 : Lavalink is ready to accept connections.
lavalinkv4  | 2024-10-15T17:51:51.954Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] io.undertow.servlet                      : Initializing Spring DispatcherServlet 'dispatcherServlet'
lavalinkv4  | 2024-10-15T17:51:51.954Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
lavalinkv4  | 2024-10-15T17:51:51.986Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 32 ms
lavalinkv4  | 2024-10-15T17:51:52.213Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.HandshakeInterceptorImpl     : Incoming connection from /172.25.0.1:42346
lavalinkv4  | 2024-10-15T17:51:52.366Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : GET /v4/websocket
lavalinkv4  | 2024-10-15T17:51:52.799Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] lavalink.server.io.SocketServer          : Connection successfully established from Moonlink.js/4.0.2 (https://github.com/Ecliptia/moonlink.js)
lavalinkv4  | 2024-10-15T17:51:53.302Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : GET /v4/info
lavalinkv4  | 2024-10-15T17:52:02.814Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.player.AudioLoaderRestHandler   : Got request to load for identifier "ytsearch:The Partysquad - Oh My (Dimitri K Remix)"
lavalinkv4  | 2024-10-15T17:52:04.345Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.player.AudioLoaderRestHandler   : Loaded playlist Search results for: The Partysquad - Oh My (Dimitri K Remix)
lavalinkv4  | 2024-10-15T17:52:04.496Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : GET /v4/loadtracks?identifier=ytsearch%3AThe+Partysquad+-+Oh+My+%28Dimitri+K+Remix%29
lavalinkv4  | 2024-10-15T17:52:04.954Z  WARN 1 --- [Lavalink] [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker    : YouTube auth tokens can't be retrieved because email and password is not set in YoutubeAudioSourceManager, age restricted videos will throw exceptions.
lavalinkv4  | 2024-10-15T17:52:05.004Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/8ohfcjgcx65x2cnh/players/718534469778145320, payload={"track":{"encoded":"QAAA8QMAT1RoZSBQYXJ0eXNxdWFkICYgUGF1bCBFbHN0YWsg4oCTIE9oIE15IChEaW1pdHJpIEsgUmVtaXgpIFtPZmZpY2lhbCBNdXNpYyBWaWRlb10AEFNwaW5uaW4nIFJlY29yZHMAAAAAAAJZkAALeDBVOFMzNW1tMzgAAQAraHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj14MFU4UzM1bW0zOAEANGh0dHBzOi8vaS55dGltZy5jb20vdmkveDBVOFMzNW1tMzgvbWF4cmVzZGVmYXVsdC5qcGcAAAd5b3V0dWJlAAAAAAAAAAA="},"volume":80}
lavalinkv4  | 2024-10-15T17:52:05.462Z ERROR 1 --- [Lavalink] [back-1-thread-1] .s.d.l.s.y.YoutubeSignatureCipherManager : Problematic YouTube player script /s/player/815edc2a/player_ias.vflset/de_DE/base.js detected (issue detected with script: no n function match). Dumped to /tmp/lavaplayer-yt-player-script13732732148074300427.js
lavalinkv4  | 2024-10-15T17:52:05.475Z  INFO 1 --- [Lavalink] [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker    : Updating YouTube visitor id (current is null).
lavalinkv4  | 2024-10-15T17:52:05.571Z  INFO 1 --- [Lavalink] [back-1-thread-1] c.s.d.l.s.y.YoutubeAccessTokenTracker    : Updating YouTube visitor id succeeded, new one is CgtJQkxaZU9kNG9GWSjF17q4BjIKCgJERRIEEgAgNjoMCAEgrr7mntH4qodn, next update will be after 600 seconds.
lavalinkv4  | 2024-10-15T17:52:47.371Z  INFO 1 --- [Lavalink] [   XNIO-1 I/O-2] lavalink.server.io.SocketServer          : Connection closed from /172.25.0.1:42346 with id 8ohfcjgcx65x2cnh -- CloseStatus[code=1006, reason=]
lavalinkv4  | 2024-10-15T17:52:47.374Z  INFO 1 --- [Lavalink] [   XNIO-1 I/O-2] lavalink.server.io.SocketContext         : Shutting down 1 playing players.
lavalinkv4  | 2024-10-15T17:52:53.491Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.HandshakeInterceptorImpl     : Incoming connection from /172.25.0.1:39432
lavalinkv4  | 2024-10-15T17:52:53.496Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : GET /v4/websocket
lavalinkv4  | 2024-10-15T17:52:53.500Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] lavalink.server.io.SocketServer          : Connection successfully established from Moonlink.js/4.0.2 (https://github.com/Ecliptia/moonlink.js)
lavalinkv4  | 2024-10-15T17:52:53.668Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : GET /v4/info
lavalinkv4  | 2024-10-15T17:52:56.439Z  INFO 1 --- [Lavalink] [  XNIO-1 task-3] l.server.player.AudioLoaderRestHandler   : Got request to load for identifier "ytsearch:The Partysquad - Oh My (Dimitri K Remix)"
lavalinkv4  | 2024-10-15T17:52:57.008Z  INFO 1 --- [Lavalink] [  XNIO-1 task-3] l.server.player.AudioLoaderRestHandler   : Loaded playlist Search results for: The Partysquad - Oh My (Dimitri K Remix)
lavalinkv4  | 2024-10-15T17:52:57.026Z  INFO 1 --- [Lavalink] [  XNIO-1 task-3] l.server.io.RequestLoggingFilter         : GET /v4/loadtracks?identifier=ytsearch%3AThe+Partysquad+-+Oh+My+%28Dimitri+K+Remix%29
lavalinkv4  | 2024-10-15T17:52:57.098Z  INFO 1 --- [Lavalink] [  XNIO-1 task-3] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/nxqyad6w8weovdib/players/718534469778145320, payload={"track":{"encoded":"QAAA8QMAT1RoZSBQYXJ0eXNxdWFkICYgUGF1bCBFbHN0YWsg4oCTIE9oIE15IChEaW1pdHJpIEsgUmVtaXgpIFtPZmZpY2lhbCBNdXNpYyBWaWRlb10AEFNwaW5uaW4nIFJlY29yZHMAAAAAAAJZkAALeDBVOFMzNW1tMzgAAQAraHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj14MFU4UzM1bW0zOAEANGh0dHBzOi8vaS55dGltZy5jb20vdmkveDBVOFMzNW1tMzgvbWF4cmVzZGVmYXVsdC5qcGcAAAd5b3V0dWJlAAAAAAAAAAA="},"volume":80}
lavalinkv4  | 2024-10-15T17:52:57.383Z  INFO 1 --- [Lavalink] [  XNIO-1 task-2] l.server.io.RequestLoggingFilter         : PATCH /v4/sessions/nxqyad6w8weovdib/players/718534469778145320, payload={"voice":{"sessionId":"2fb2752fe2f22db09c12ab3911b9d3c0","token":"e0d1b4645d70b72e","endpoint":"rotterdam2744.discord.media:443"}}
1Lucas1apk commented 6 days ago

Could you provide me with the play code you made?

NekoSuneVR commented 6 days ago

play code is above nothing changed

NekoSuneVR commented 6 days ago

only thing changed is this

a common error, just change this here and it should solve the problem

sendPayload: (guildId, payload) => {
    const guild = client.guilds.cache.get(guildId);
    if (guild) guild.shard.send(JSON.parse(payload));
  },
1Lucas1apk commented 6 days ago

Could you provide me with the play code?

NekoSuneVR commented 6 days ago
const { getGuildToggle } = require("../../utils/funt-ext.js");
const {
  EmbedBuilder,
  PermissionFlagsBits,
  ApplicationCommandType,
  ApplicationCommandOptionType
} = require("discord.js");

function isSpotifyURL(input) {
  try {
    const url = new URL(input);
    return url.hostname === "open.spotify.com";
  } catch (error) {
    return false;
  }
}

module.exports = {
  name: "play",
  description: "Play Music From Spotify",
  type: ApplicationCommandType.ChatInput,
  toggleOff: false,
  developersOnly: false,
  patreonOnly: false,
  patreonManualWhitelist: [
    "1054148043781451776",
    "540706221645103104",
    "100463282099326976",
    "124495978962092037",
    "901415888060825681",
    "588083360598065193",
    "342864764579610626",
    "506525503960776725",
    "191671340149899264",
    "96669710568951808"
  ],
  userpermissions: [
    PermissionFlagsBits.SendMessages,
    PermissionFlagsBits.ViewChannel
  ],
  botpermissions: [
    PermissionFlagsBits.Connect,
    PermissionFlagsBits.Speak,
    PermissionFlagsBits.SendMessages,
    PermissionFlagsBits.ViewChannel
  ],
  cooldowns: 2000,
  options: [
    {
      name: "q",
      description: "Spotify URL or Song Name - Title",
      type: ApplicationCommandOptionType.String,
      required: true
    }
  ],

  run: async (client, interaction) => {
    const [guildsettingstoggle] = await getGuildToggle(interaction.guild.id).catch(console.error);

    if (guildsettingstoggle.musicToggle === 0) {
      return interaction.reply(
        "Server Administrator Disabled Music Integration on this Server. Please go to our Dashboard to re-enable it."
      );
    }

    await interaction.deferReply({ ephemeral: false });

    const query = interaction.options.getString("q");

    /*if (!isSpotifyURL(query)) {
      return interaction.editReply("Only Spotify URLs are allowed.");
    }*/

    if (!interaction.member.voice.channel) {
        return interaction.editReply({
            content: `Error: You must be in a voice channel to execute this command.`,
            ephemeral: true
        });
    }

    const player = client.manager.createPlayer({
        guildId: interaction.guild.id,
        voiceChannelId: interaction.member.voice.channel.id,
        textChannelId: interaction.channel.id,
        autoPlay: true
    });

    if (!player.connected) {
        player.connect({
            setDeaf: true, // Deafens the bot upon joining
            setMute: false // Ensures the bot isn't muted
        });
    }

    await interaction.editReply(`🔍 **Searching...** \`${query}\``);

    const res = await client.manager.search({
        query,
        requester: interaction.user.id
    });

    if (res.loadType === "loadfailed") {
        return interaction.editReply({
            content: `Error: Failed to load the requested track.`,
            ephemeral: true
        });
    } else if (res.loadType === "empty") {
        return interaction.editReply({
            content: `Error: No results found for the query.`,
            ephemeral: true
        });
    }

    if (res.loadType === "playlist") {
        interaction.editReply({
            content: `Playlist ${res.playlistInfo.name} has been added to the queue.`
        });

        for (const track of res.tracks) {
            player.queue.add(track); // Add all tracks from the playlist to the queue
        }
    } else {
        player.queue.add(res.tracks[0]); // Add the first track from the search results
        interaction.editReply({
            content: `Track added to the queue: ${res.tracks[0].title}`
        });
    }

    if (!player.playing) {
        player.play(); // Start playing if not already doing so
    }
  }
};

like I say all rest base code from your example in direct path

only made as command file that's what basely layout you have in example

told u scroll, that's only code not changed >.>

1Lucas1apk commented 6 days ago

the voiceState information is arriving after the track request, this causes it to not play

NekoSuneVR commented 6 days ago

well same code in readme, what i copyed over just yours is client.moonlink when mine is client.manager nothing new

1Lucas1apk commented 5 days ago

I will make a change tomorrow to solve this problem