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

问题描述

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

解决方法

使用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}`);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...