如何使用 discord.js 音乐机器人在歌曲中寻找一个点?
How to seek to a point in a song with discord.js music bot?
我正在尝试用 ytdl-core
制作一个 discord.js
音乐机器人。我不太确定如何在使用命令时查找歌曲中的当前时间,并且搜索帮助并没有真正起到多大作用。该命令的工作方式类似于 !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
*/
Discord.js v12
VoiceConnection#play
takes a second 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})
Discord.js V13
你可以这样使用 fluent-ffmpeg :
const fluentFfmpeg = require('fluent-ffmpeg')
let ms = 90000;
let song = ytdl('some youtube link', {quality: 'highestaudio'})
let editedSong = fluentFfmpeg({source: song}).toFormat('mp3').setStartTime(Math.ceil(ms/1000)) // set the song start time
queue.play(editedSong)
我正在尝试用 ytdl-core
制作一个 discord.js
音乐机器人。我不太确定如何在使用命令时查找歌曲中的当前时间,并且搜索帮助并没有真正起到多大作用。该命令的工作方式类似于 !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
*/
Discord.js v12
VoiceConnection#play
takes a second 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})
Discord.js V13
你可以这样使用 fluent-ffmpeg :
const fluentFfmpeg = require('fluent-ffmpeg')
let ms = 90000;
let song = ytdl('some youtube link', {quality: 'highestaudio'})
let editedSong = fluentFfmpeg({source: song}).toFormat('mp3').setStartTime(Math.ceil(ms/1000)) // set the song start time
queue.play(editedSong)