Search code examples
javascriptnode.jsdiscorddiscord.jsvoice

Discord.js Voice connection.destroy() error


I try to create a "Stop" commands using a @discordjs/voice, it's working with an error. i tried so many times adding some catching, but still error. This is my code:

async function stop(message) {
  try {
    if (!message.member.voice.channelId)
      return message.reply("You are not in a voice channel!");

    if (
      message.guild.me.voice.channelId &&
      message.member.voice.channelId !== message.guild.me.voice.channelId
    )
      return message.reply("You are not in my voice channel!");
    if (!message.guild.me.voice.channelId)
      return message.reply("I'm not playing anything!");

    let embed = new MessageEmbed()
      .setColor(color.warn)
      .setDescription(
        `**⏹️ | Stopped playing in <#${message.guild.me.voice.channelId}>**`
      );

    const connection = await getVoiceConnection(message.guildId);
    if (!connection)
      return message.reply(`There aren't any active radio in this Server`);

    message.reply({ embeds: [embed] });

    return await connection.destroy(); // Trigger of the error
  } catch (err) {}
}

This is the error i received in the console:

reject Promise { { ip: '34.136.228.183', port: 51364 } } Error: Cannot perform IP discovery - socket closed
    at Socket.<anonymous> (/home/runner/disbot/node_modules/@discordjs/voice/dist/index.js:1:6361)
    at Object.onceWrapper (node:events:509:28)
    at Socket.emit (node:events:402:35)
    at socketCloseNT (node:dgram:755:8)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)

Solution

  • Okay, i found the answer

    So we must set this code into your main file (like index.js, etc) and it will work like a champ.

    process.on("multipleResolves", (type, promise, reason) => {
        if (reason.toLocaleString() === "Error: Cannot perform IP discovery - socket closed") return;
    });
    

    The error was cancelled to show the error by process.on("multipleResolves")