问题描述
我正在尝试使用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
(返回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}`);