时间命令对歌曲持续时间说`NAN`:`NaN`

问题描述 投票:0回答:1

这是时间代码,StreamTime是自动播放歌曲的时间,song.duration是音乐持续时间。我的机器人说NaNNaN代表song.duration

module.exports = {
  name: "time",
  description: "Show music time",
  execute(message, song, duration) {

    const queue = message.client.queue.get(message.guild.id);       
    const dispatcher = queue.connection.dispatcher

    message.channel.send({
      embed: {
        color: 39935,  //random color between one and 16777214 (dec)
        author: {},
        title: "Time ⏳",
        color: 39935,
        description: `${Math.floor(dispatcher.streamTime / 60000)}:${Math.floor((dispatcher.streamTime % 60000)/1000) <10 ? '0'+Math.floor((dispatcher.streamTime % 60000)/1000) : Math.floor((dispatcher.streamTime % 60000)/1000)}  Duration: ${Math.floor(song.duration/60)}:${song.duration%60}`,          
        timestamp: new Date(),
        footer: {
          icon_url: message.client.user.avatarURL(),
          text: "© test"
        }
      }
    }); 
  }}

“屏幕截图”

discord.js
1个回答
0
投票

似乎song.duration似乎不是数字。

您需要先将其转换为数字

description: `${Math.floor(dispatcher.streamTime / 60000)}:${Math.floor((dispatcher.streamTime % 60000)/1000) <10 ? '0'+Math.floor((dispatcher.streamTime % 60000)/1000) : Math.floor((dispatcher.streamTime % 60000)/1000)}  Duration: ${Math.floor(parseInt(song.duration)/60)}:${parseInt(song.duration)%60}`,
© www.soinside.com 2019 - 2024. All rights reserved.