使用 Discord.js 音乐机器人获取视频的当前时间戳?

Getting the current timestamp for a video with a Discord.js music bot?

我正在尝试使用 discord.js & ytdl-core 创建一个音乐机器人。我想在使用名为 !nowplaying 的命令时显示当前时间戳。但是,我不确定我是怎么得到时间的。我的代码:

//bot.queue is a collection, and contains some attributes, like songs (array) and connection (ytdl)
let queue = bot.queue.get(message.guild.id); 

const time = queue.connection.streamTime; //Doesn't work!

//Convert time here, then output

message.channel.send(`Now Playing - ${queue.songs[0].title} - ${time}`);

我试过 queue.connection.streamTime 和其他方法,但都没有用

使用voiceConnection#dispatcher(它returns一个StreamDispatcher)而不是voiceConnection

//bot.queue is a collection, and contains some attributes, like songs (array) and connection (ytdl)
let queue = bot.queue.get(message.guild.id); 

const time = queue.connection.dispatcher.streamTime; //Doesn't work!

//Convert time here, then output

message.channel.send(`Now Playing - ${queue.songs[0].title} - ${time}`);