问题描述
我正在尝试用 ytdl-core
制作一个 discord.js
音乐机器人.我不太确定在使用命令时如何在歌曲中寻找当前时间,并且搜索帮助并没有真正做太多.该命令的工作方式类似于 !seek 1:30
.
I am trying to make a discord.js
music bot with ytdl-core
. I am not quite sure how to seek to a current time in a song when using a command, and searching for help hasn't really done much. The command would work like !seek 1:30
.
我想知道的是:
a) 调度程序是否包含搜索功能?
What I am looking to find out is either:
a) Does the dispatcher include a seek function?
//i.e like below
let ms = 90000; //would be converted from arguments
queue.connection.dispatcher.seek(ms) //Does this exist???
或 b) 如何在特定时间开始播放歌曲?
or b) How can I start a song at a certain time?
//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
*/
推荐答案
Discord.js v12
VoiceConnection#play
需要一秒钟 StreamOptions
论点.您可以使用 seek
属性指定要查找的秒数:
Discord.js v12
VoiceConnection#play
takes a second StreamOptions
argument. You can specify how many seconds you want to seek with the seek
property:
// 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})
这篇关于如何使用 discord.js 音乐机器人在歌曲中寻找一个点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!