JS:Seek命令不搜索音乐机器人



Seek命令对音乐机器人不起作用,它只是在重播歌曲。如果用户输入了seek命令,它会一直持续到歌曲的1:00。我没有出错。以下是代码:

module.exports = {
name : 'seek',
description: 'Pick a time',
usage : "<time>",
run : async (client , message  , args) => {
const serverQueue = message.client.queue.get(message.guild.id);
let channel = message.member.voice.channel;
if (!channel)return message.channel.send("Join a voice channel to play music!")
if (!serverQueue) return message.channel.send("No songs to seek");
try {
const curDuration = (serverQueue.songs[0].durationm * 60000) + ((serverQueue.songs[0].durations % 60000) * 1000);
const choiceDur = args.join(" ").split(":");
if (choiceDur.length < 2) return message.channel.send("No duration provided or invalid ?");
const optDurr = (parseInt(choiceDur[0], 10) * 60000) + ((parseInt(choiceDur[1], 10) % 60000) * 1000);
if (optDurr > curDuration) return message.channel.send("Your duration is too big");
serverQueue.songs.splice(1, 0, serverQueue.songs[0]);
return serverQueue.connection.dispatcher.end()
} catch (e) {
return message.channel.send(`Oh no an error occured : `${e.message}` try again later`)
}
}
}

感谢您的帮助!!!

我试过了serverQueue.connection.dispatcher.seek()serverQueue.connection.dispatcher.seek(choiceDur)serverQueue.connection.dispatcher.end(choiceDur)serverQueue.connection.dispatcher.end()

要明确的是,connection.dispatcher是流跟随文档,没有名为seek()end()的方法。

要在特定时间播放歌曲,您应该停止当前流,并在特定时间开始新的流。

解决方案:

serverQueue.connection.play(serverQueue.currentSong, {seek: ms / 1000});
//serverQueue.currentSong is stream type

有关更多信息:VoiceConnection#play需要第二个StreamOptions参数注意不是每种类型的流都可以搜索

最新更新