Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未定义time.minutes和time.seconds_Javascript_Discord.js - Fatal编程技术网

Javascript 未定义time.minutes和time.seconds

Javascript 未定义time.minutes和time.seconds,javascript,discord.js,Javascript,Discord.js,因此,我制作了一个带有冷却时间的工作命令,它精确地显示了您需要等待多长时间才能再次工作。冷却时间是有效的,但它表示time.seconds和time.minutes是未定义的。这是我的密码: const Discord = require("discord.js"); const db = require('quick.db') const ms = require("ms"); module.exports = class economy { constructor(){ t

因此,我制作了一个带有冷却时间的工作命令,它精确地显示了您需要等待多长时间才能再次工作。冷却时间是有效的,但它表示time.seconds和time.minutes是未定义的。这是我的密码:

const Discord = require("discord.js");
const db = require('quick.db')
const ms = require("ms");

module.exports = class economy {
  constructor(){
      this.name = 'work',
      this.alias = ['work'],
      this.usage = 's!work',
      this.description = 'Work to get paid',
      this.runnable = 'true'
}

async run(bot, message, args) {

let timeout = 600000 
let amount = Math.floor(Math.random() * 25) + 15;

var jobs = ["Miner", "Bartender", "Cashier", "Cleaner", "Drugdealer", "Assistant", "Nurse", "Cleaner", "Teacher", "Accountants", "Security Guard", "Sheriff", "Lawyer", "Dishwasher", "Electrician", "Singer", "Dancer"];

let work = await db.fetch(`work_${message.author.id}`);

if (work !== null && timeout - (Date.now() - work) > 0) {
    let time = ms(timeout - (Date.now() - work));

    message.channel.send(`You already worked, try again in **${time.minutes}m ${time.seconds}s**!`)
} else {
  var job = jobs[Math.floor(Math.random() * jobs.length)];

  message.channel.send(`You worked as a ${job} and earned ${amount} <:shart:646075915293687810>`)

db.add(`money_${message.author.id}`, amount)
db.set(`work_${message.author.id}`, Date.now())

}
}   
}

我怎样才能解决这个问题

根据,ms功能的结果中没有分钟和秒字段。如果我正确理解了您的用例,而不是**${time.minutes}m${time.seconds}**,您应该只提供**{time}**.

const ms=requireparse ms

但如何获得秒数?在许多机器人程序中,我看到使用了time.minutes和time.seconds?请看一看-它只是对我们案例中最大的单位分钟数进行四舍五入,并返回相应的状态。如果你想显示秒,无论如何,你应该考虑另一个解决这个任务的方法,恐怕我不能提供在此刻你可以检查这个解决方案:嗨,欢迎到堆栈溢出!请坐飞机。谢谢你回答一个问题,但是你能补充一些关于你的代码如何解决这个问题的解释吗?要正确格式化代码,请参见此。