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

时间:2020-09-02 17:14:03

标签: discord.js ytdl

我正在尝试使用discord.jsytdl-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和其他方法,但是它们没有用

1 个答案:

答案 0 :(得分:1)

使用voiceConnection#dispatcher(返回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}`);