【发布时间】: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