【问题标题】:Getting the current timestamp for a video with a Discord.js music bot?使用 Discord.js 音乐机器人获取视频的当前时间戳?
【发布时间】:2020-12-21 21:57:21
【问题描述】:

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

【问题讨论】:

    标签: discord.js ytdl


    【解决方案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}`);
    

    【讨论】:

      猜你喜欢
      • 2021-11-29
      • 2020-06-06
      • 2021-07-25
      • 2020-09-22
      • 2023-03-15
      • 2020-08-04
      • 2020-12-01
      • 1970-01-01
      • 2020-06-27
      相关资源
      最近更新 更多