首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JS: Seek command not Seek for music bot

JS: Seek command not Seek for music bot
EN

Stack Overflow用户
提问于 2021-06-03 10:00:19
回答 1查看 120关注 0票数 0

Seek命令不适用于音乐机器人,它只是在重放这首歌。如果用户放了这首歌,seek命令就会转到像1:00这样的时间。我没有收到任何错误。代码如下:

代码语言:javascript
复制
 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()

EN

回答 1

Stack Overflow用户

发布于 2021-06-03 15:46:05

明确地说,connection.dispatcher是流跟随docs,没有叫做seek()end()的方法。

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

解决方案:

代码语言:javascript
复制
serverQueue.connection.play(serverQueue.currentSong, {seek: ms / 1000});
//serverQueue.currentSong is stream type

有关更多信息:VoiceConnection#play接受第二个StreamOptions参数。注意:流的类型并不是每种类型都可以查找

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67814488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档