【问题标题】:Discord.js Voice connection.destroy() errorDiscord.js 语音 connection.destroy() 错误
【发布时间】:2022-01-17 12:35:39
【问题描述】:

我想创建一个“无线电”命令。我使用了一个名为@discordjs/voice 的包。我希望用户输入quit,机器人将离开机器人所在的频道。我正在使用此代码:

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();
  } catch (err) {}
}

这是错误:

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)

注意:机器人正在离开语音频道。但机器人在控制台中返回错误。

感谢您的回答!

【问题讨论】:

  • 尝试从您的 connection.destroy() 呼叫中删除 await。它返回无效,而不是承诺。
  • @GentleAutumnRain 仍然错误

标签: javascript node.js discord discord.js voice


【解决方案1】:

我有办法:

在 index.js(或主文件)中你可以这样输入:

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

错误被process.on("multipleResolves")取消显示错误

【讨论】:

    猜你喜欢
    • 2021-09-09
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 2021-12-06
    • 2021-05-16
    • 1970-01-01
    • 2019-01-06
    相关资源
    最近更新 更多