不和谐音乐机器人加入语音频道,亮起绿色但没有任何音频.前2周效果很好.控制台中没有错误



我用node.js编写了一个机器人。我用Crawl的例子来制作他的音乐机器人。我做了与他相似的事情。在我完成构建后,一切都工作了。每隔一个命令和play命令。但是现在 2 周后机器人加入了语音通道,亮起绿色但没有声音。我更新了ffmpeg@discordjs/opusffmpeg-static并从ffmpeg下载了完整的版本,但机器人仍然没有音频。queuevolumenowplayingskipshuffleloop一切正常。但是在我使用播放命令获得视频或播放列表后,机器人仅加入绿色亮起但没有音频。因此,机器人最终会获取网址,获取视频,获取他需要播放的所有内容。但加盟后,他不再使用这些信息来玩。此外,在歌曲结束后,他不会离开语音频道。

function play(guild, song) {
try {
const ServerMusicQueue = queue.get(guild.id);
if (!song) {
ServerMusicQueue.textchannel.send(`🎶 Queue ended and left the Voicechannel!`).then(message => message.delete(6000));
ServerMusicQueue.voiceChannel.leave()
queue.delete(guild.id)
return;
}
const dispatcher = ServerMusicQueue.connection.playStream(ytdl(song.url, { filter: 'audioonly', quality: 'highestaudio', highWaterMark: 1 << 25 }))
.on('end', () => {
var loopset = JSON.parse(fs.readFileSync("./rqs/loopset.json", "utf8"))
if (!loopset[message.guild.id]) {
loopset[message.guild.id] = {
loopset: config.loopset
}
}
var loop2 = loopset[message.guild.id].loopset;
if (loop2 === "true") {
play(guild, ServerMusicQueue.songs[0])
return;
}
ServerMusicQueue.songs.shift()
play(guild, ServerMusicQueue.songs[0])
})
.on('error', error => {
console.error(error)
});
dispatcher.setVolumeLogarithmic(ServerMusicQueue.volume / 5);
ServerMusicQueue.textchannel.send(`🎶 Start playing: **${song.title}**`).then(message => message.delete(8000));
} catch (error2) {
console.log(error2)
}
}
async function handleVideo(video, message, voiceChannel, playlist = false) {
const ServerMusicQueue = queue.get(message.guild.id)
const song = {
id: video.id,
title: Util.escapeMarkdown(video.title),
url: `https://www.youtube.com/watch?v=${video.id}`,
duration: video.duration,
requested: message.author.username
};
if(!ServerMusicQueue) {
const queueConstruct = {
textchannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true,
};
queue.set(message.guild.id, queueConstruct);
queueConstruct.songs.push(song)
try {
var connection = await voiceChannel.join()
queueConstruct.connection = connection;
play(message.guild, queueConstruct.songs[0])
var loopset = JSON.parse(fs.readFileSync("./rqs/loopset.json", "utf8"))
if(!loopset[message.guild.id]){
loopset[message.guild.id] = {
loopset: config.loopset
}
}
var loop2 = loopset[message.guild.id].loopset;
if(loop2 === "true") {
loopset[message.guild.id] = {
loopset: "false"
}
fs.writeFile("./rqs/loopset.json", JSON.stringify(loopset), (err) => {
if (err) console.log(err)
});
}
} catch (error) {
console.error(`Voicechannel join: ${error}`)
queue.delete(message.guild.id);
message.channel.send("Error with joining the Voicechannel!").then(message => message.delete(5000));
message.delete(4000).catch(console.error);
return;
}
} else {
ServerMusicQueue.songs.push(song);
if(playlist) return undefined;
else return message.channel.send(`🎶 **${song.title}** has been added to the queue!`).then(message => message.delete(5000));
}
return;
}

包.json

"dependencies": {
"@discordjs/opus": "^0.3.2",
"bufferutil": "^4.0.1",
"colors": "^1.4.0",
"discord.js": "^11.6.4",
"discord.js-commando": "^0.10.0",
"discord.js-musicbot-addon": "^13.9.1",
"discordjs-prompter": "^1.3.1",
"ffmpeg-static": "^4.2.2",
"file-system": "^2.2.2",
"html-entities": "^1.3.1",
"m3u8stream": "^0.7.0",
"miniget": "^1.7.0",
"ms": "^2.1.2",
"node-opus": "^0.3.3",
"npm": "^6.14.5",
"simple-youtube-api": "^5.2.1",
"sqlite": "^3.0.3",
"sqlite3": "^4.1.0",
"superagent": "^5.2.2",
"yt-search": "^1.1.2",
"ytdl-core": "^2.1.3"
}

尝试获取 ytdl 核心,它可能会解决问题。

npm i ytdl-core

如果这不能解决问题,请尝试获取 Discord-YTDL-Core(确保您已安装 ytdl-core(

npm i discord-ytdl-core