微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用discord.js音乐机器人在歌曲中寻找要点?

如何解决如何使用discord.js音乐机器人在歌曲中寻找要点?

我正在尝试使用discord.js一个ytdl-core音乐机器人。我不太确定在使用命令时如何在歌曲中寻找当前时间,而寻求帮助的确做得并不多。该命令将像!seek 1:30一样工作。

我要查找的是:
a)调度程序是否包含查找功能

//i.e like below
let ms = 90000; //would be converted from arguments
queue.connection.dispatcher.seek(ms) //Does this exist???

或b)如何在特定时间开始播放歌曲?

//Add the song again,but with a timestamp,and end current song
let seekedSong = queue.songs[0];
seekedSong.startTime = 90000; 
queue.songs.unshift(seekedSong);
queue.connection.dispatcher.end()
/* However,how do I start a song given a start time?
 * 
 * In my play.js file,which plays the next song in the queue automatically,* how can i tell it to start at a time? I tried dispatcher.end() and supplying 
 * a youtube link with ?t={sec}s,but that didnt work
 */

解决方法

VoiceConnection#play需要第二个StreamOptions参数。您可以使用seek属性指定要搜索的秒数:

// When playing the song:
const stream = ytdl('https://youtu.be/dQw4w9WgXcQ')
// Store the stream somewhere
queue.currentSong = stream

// When seeking:
queue.connection.play(queue.currentSong,{seek: ms / 1000})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。